Skip to content Skip to sidebar Skip to footer

Very Weird Chrome Behavior In An Open (focused) "select" Element

Here's a

Solution 1:

Change the code to:

functionfoo() {
    var s = $('select option:selected');
}

setInterval(foo, 200);

Not sure why exactly it does this, but my guess would be that it's related to the way pseudoselectors work in jQuery. They're implemented as functions which are paired with the name of the selector (In this case "selected"). Consequently they are run against every possible element in the context (not just those which could potentially be selected).

Maybe there some sort of weird ghost element against which the "selected" pseudoselector is being executed when it shouldn't. The solution here is that I restrict the context to options before doing the pseudoselector. Always a good thing to do.

Post a Comment for "Very Weird Chrome Behavior In An Open (focused) "select" Element"