Ticket #12600 (closed bug: fixed)
jQuery('select').is('[value="value"]') works inconsistently depending on number of elements returned
| Reported by: | dschoutens@… | Owned by: | gibson042 |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.9 |
| Component: | attributes | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocking: | #11115 | Blocked by: |
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
comment:1 Changed 8 months ago by rwaldron
- Owner set to rwaldron
- Status changed from new to assigned
comment:2 Changed 8 months ago by rwaldron
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)
comment:3 follow-up: ↓ 4 Changed 8 months ago by 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/
comment:4 in reply to: ↑ 3 Changed 8 months ago by dschoutens@…
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 7 months ago by timmywil
- Priority changed from undecided to low
- Component changed from unfiled to attributes
comment:6 Changed 6 months ago by gibson042
- 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 6 months ago by gibson042
- Priority changed from low to blocker
- Milestone changed from None to 1.9
comment:8 Changed 6 months ago by gibson042
The hook should be moved to https://github.com/jquery/jquery-compat/.
comment:9 Changed 6 months ago by rwaldron
- Owner changed from rwaldron to gibson042
Reassigning to gibson042, seems like you have a better handle on this
comment:10 Changed 6 months ago by gibson042
comment:11 Changed 6 months ago by gibson042
#11735 is a duplicate of this ticket.
comment:12 Changed 5 months ago by Richard Gibson
- Status changed from assigned to closed
- Resolution set to fixed
Fix #12600: don't use value property in place of value attribute. Close gh-1063.
Changeset: 2c40fdd4a852fe6ee16feaa3bb6d7d49c7a02606
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
