Ticket #11115 (closed bug: fixed)
".is()" and ".filter()" disagree on attribute selector "[checked]"
|Reported by:||Pointy||Owned by:||gibson042|
The selector "[checked]" is treated differently by ".is()" and ".filter()", in a strange and mysterious way when the "checked" property (not attribute) is set; that is, on checkbox inputs that in the DOM lack the "checked" attribute but which have been checked by user action (or possibly by explicit setting of the "checked" property). If you've got a jQuery object matching one DOM node (and just one), then ".is()" and ".filter()" are in agreement. That is, if a checkbox is checked only after the DOM is built, then both ".is()" and ".filter()" agree that the selector "[checked]" should not match the node.
However, when the jQuery object selects more than one checkbox, then the behavior of ".filter()" changes. Though each checkbox, if tested individually with ".is('[checked]')" would appear to not match, a call to ".filter('checked')" will nevertheless include them in the result if they've been dynamically updated.
Here is a jsfiddle to explore the issue: http://jsfiddle.net/mgfxe/2/
Now I realize that "[checked]" is not really correct or useful or anything, but the behavior does seem inconsistent; I would imagine that any node that makes it through a selector-based ".filter()" should be guaranteed to pass a ".is()" test for the same selector. The funny thing is that the implementation boils down to calls to "Sizzle.matches()" or "Sizzle.matchesSelector()" (I think) and both of those are nearly identical.
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to selector
comment:11 Changed 13 months ago by timmywil
- Owner set to timmywil
- Status changed from open to assigned
comment:15 Changed 12 months ago by gibson042
- Blocked by 12600 added