Skip to main content

Bug Tracker

Side navigation

#7128 closed bug (fixed)

Opened October 07, 2010 09:05PM UTC

Closed September 19, 2011 07:43PM UTC

attribute selector is inconsistent between qSA and Sizzle due to use of DOM properties

Reported by: adipose Owned by: timmywil
Priority: blocker Milestone: 1.7
Component: selector Version: 1.4.3
Keywords: equal selector Cc:
Blocked by: Blocking:
Description

If I set an input value with javascript, the jquery selector does not select it unless I use an incorrectly formatted selector.

This occurs in Chrome 7.0.517.24, Firefox 3.6.10, Firefox 4.0b6, Opera 10.62 and Safari 4.0 (Win32).

IE8, however, does work properly.

Correct selector:

$("[value=a]") does not work.

Incorrect selector:

$("&[value=a]") does work.

$("@[value=a]") does work.

etc.

See the attached example. It works at first, but after the javascript changes the value, it gets wrong results (except in IE8).

Attachments (2)
  • test.html (0.9 KB) - added by adipose October 07, 2010 09:15PM UTC.
  • test.php (0.9 KB) - added by adipose October 07, 2010 09:08PM UTC.
Change History (32)

Changed October 07, 2010 09:13PM UTC by adipose comment:1

Added file as html

Changed October 07, 2010 11:00PM UTC by snover comment:2

priority: highlow
summary: Jquery selector broken on values set with javascript?value attribute selector is inconsistent between qSA and Sizzle due to use of DOM properties

The value attribute in HTML actually corresponds to the defaultValue DOM property.

Presumably, the reason the “incorrect” selectors work is because the browser’s native querySelectorAll function fails (due to their invalidity) and jQuery falls back to using Sizzle’s slow path.

The real bug here sounds like the fact that Sizzle inspects DOM 2 HTML properties instead only using getAttribute, and perhaps also that IE8 is doing something else it shouldn’t be.

Changed October 08, 2010 04:50PM UTC by adipose comment:3

"The value attribute in HTML actually corresponds to the defaultValue DOM property."

Is this to say, a jquery selector that inspects value will only ever look at the defaultValue DOM property?

When using .filter(), one can select based on value and not just defaultValue. Is this also a bug?

What is the proper way to select by value if value has been changed?

Changed October 08, 2010 07:44PM UTC by snover comment:4

The jQuery attribute selector [value="foo"] should always inspect the HTML attribute value (which corresponds to the DOM property defaultValue), not the DOM property value which corresponds to the user- or script-modified state of the control.

To select by the current value, you would do something like:

$('input:text').filter(function () { return this.value === "foo"; })

Changed October 08, 2010 07:50PM UTC by adipose comment:5

Thank you, I did not realize this, before.

However, I would like to point out that

$('input').filter("[value=foo]")

Works. Is this supposed to work, or will it break once the other bug is corrected?

Changed October 14, 2010 05:43AM UTC by snover comment:6

status: newopen

Changed October 15, 2010 02:39AM UTC by addyosmani comment:7

#6826 is a duplicate of this ticket.

Changed October 15, 2010 04:11AM UTC by snover comment:8

blocking: → 6954

Changed October 15, 2010 04:20AM UTC by snover comment:9

#6948 is a duplicate of this ticket.

Changed October 15, 2010 04:21AM UTC by snover comment:10

blocking: 6954

Changed October 15, 2010 04:21AM UTC by snover comment:11

#6954 is a duplicate of this ticket.

Changed October 15, 2010 04:25AM UTC by snover comment:12

#6939 is a duplicate of this ticket.

Changed October 15, 2010 04:26AM UTC by snover comment:13

#5810 is a duplicate of this ticket.

Changed October 15, 2010 10:25PM UTC by snover comment:14

#3399 is a duplicate of this ticket.

Changed October 15, 2010 10:26PM UTC by snover comment:15

milestone: 1.4.31.next
priority: lowblocker
version: 1.4.21.4.3

Many more duplicates are listed in #3399.

Changed October 15, 2010 10:26PM UTC by snover comment:16

summary: value attribute selector is inconsistent between qSA and Sizzle due to use of DOM propertiesattribute selector is inconsistent between qSA and Sizzle due to use of DOM properties

Changed October 17, 2010 09:27PM UTC by snover comment:17

milestone: 1.4.41.5

Retargeting for 1.5.

Changed October 27, 2010 05:24AM UTC by addyosmani comment:18

#6470 is a duplicate of this ticket.

Changed November 12, 2010 10:29PM UTC by snover comment:19

blocking: → 7485

(In #7485) This is something on the roadmap for 1.5. .attr will be rewritten along with Sizzle to stop matching on the DOM properties, so this will all be happily consistent again.

Changed January 17, 2011 04:50PM UTC by john comment:20

milestone: 1.51.6

This is getting bumped to 1.6 when the $.attr rewrite happens.

Changed April 15, 2011 04:06AM UTC by timmywil comment:21

blocking: 7485

Changed April 15, 2011 04:12AM UTC by timmywil comment:22

#5930 is a duplicate of this ticket.

Changed April 17, 2011 08:37PM UTC by john comment:23

milestone: 1.61.next

Changed April 25, 2011 04:43AM UTC by timmywil comment:24

#8960 is a duplicate of this ticket.

Changed May 03, 2011 01:48PM UTC by timmywil comment:25

#9062 is a duplicate of this ticket.

Changed May 03, 2011 01:55PM UTC by timmywil comment:26

#8740 is a duplicate of this ticket.

Changed May 12, 2011 07:43PM UTC by timmywil comment:27

blocking: → 9261

Changed May 17, 2011 04:20PM UTC by timmywil comment:28

milestone: 1.next1.7

Changed June 20, 2011 02:04PM UTC by timmywil comment:29

#9623 is a duplicate of this ticket.

Changed July 25, 2011 04:02PM UTC by john comment:30

owner: → timmywil
status: openassigned

Changed September 11, 2011 10:23PM UTC by timmywil comment:31

#9171 is a duplicate of this ticket.

Changed September 19, 2011 07:43PM UTC by timmywil comment:32

resolution: → fixed
status: assignedclosed

Override Sizzle attribute retrieval with jQuery.attr. Fixes #5637, #7128, #9261, #9570, #10178.

Bug fixed on the side: $(window).is('a') was throwing an exception. Fixes #10178.

Changeset: 92405d4f5ffe9ec1f26f280303783014948438c5