Opened 10 years ago
Closed 10 years ago
#12600 closed bug (fixed)
jQuery('select').is('[value="value"]') works inconsistently depending on number of elements returned
Reported by: | Owned by: | gibson042 | |
---|---|---|---|
Priority: | blocker | Milestone: | 1.9 |
Component: | attributes | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: | #11115 |
Description
I have distilled the issue as much as possible in a jsFiddle: http://jsfiddle.net/Mj23Q/
Say we've got a jQuery object saved to a variable, x.
If x contains multiple select elements and at least one of them has a value, "1", then:
x.is('[value=1]')
will return true, since at least one select element matches the value attribute selector given. However, if x only contains a single element, and that element is a select with a value of "1", the same function returns false.
I tested and was able to reproduce this in Chrome 21, Chrome 24 (Canary), Firefox 15, and Internet Explorer 9 for all versions of jQuery provided in jsFiddle.
Sorry if this is a duplicate bug, but I really tried to find an existing bug report. My search-fu might be a little off today.
Change History (12)
comment:1 Changed 10 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | new → assigned |
comment:2 Changed 10 years ago by
comment:3 follow-up: 4 Changed 10 years ago by
This might help: it seems the bug is not specific to the .is() function, but also affects .filter() (at least...)
I updated the jsFiddle to demonstrate: http://jsfiddle.net/Mj23Q/13/
comment:4 Changed 10 years ago by
Replying to anonymous:
This might help: it seems the bug is not specific to the .is() function, but also affects .filter() (at least...)
I updated the jsFiddle to demonstrate: http://jsfiddle.net/Mj23Q/13/
That was me... forgot to specify my email in my comment.
comment:5 Changed 10 years ago by
Component: | unfiled → attributes |
---|---|
Priority: | undecided → low |
comment:6 Changed 10 years ago by
Blocking: | 11115 added |
---|
The expectations in the comments of that fiddle are erroneous... select[value=…]
shouldn't match anything, because most select elements—and those in particular—don't have attributes named "value".
This ticket is the attrHooks
equivalent of #11115: native Sizzle always gets it right, jQuery only does so when jQuery.filter
calls a qSA-backed matchesSelector
in the single-element case: http://jsfiddle.net/Mj23Q/43/
comment:7 Changed 10 years ago by
Milestone: | None → 1.9 |
---|---|
Priority: | low → blocker |
comment:8 Changed 10 years ago by
The hook should be moved to https://github.com/jquery/jquery-compat/.
comment:9 Changed 10 years ago by
Owner: | changed from Rick Waldron to gibson042 |
---|
Reassigning to gibson042, seems like you have a better handle on this
comment:12 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fix #12600: don't use value property in place of value attribute. Close gh-1063.
Changeset: 2c40fdd4a852fe6ee16feaa3bb6d7d49c7a02606
Not 100%, but this change might be the issue: https://github.com/jquery/sizzle/commit/6e524a5915a8a5dda1969898749c81d0fae64e6e
(this is mostly a note to myself as I dig through this)