Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#9159 closed bug (duplicate)

Attribute selectors not working in IE6-7 (really)

Reported by: jamietre Owned by: jamietre
Priority: high Milestone: 1.next
Component: selector Version: 1.6
Keywords: Cc:
Blocked by: Blocking:


This is reopening Ticket #9156. Sorry about the confusion - it has been difficult to determine the problem since I can't use jsFiddle with IE6.

There is a bug in the Sizzle code that is used when .querySelectorAll is not available to select attributes that have no value.

Original code at line 4465 in 1.6.0:

4464   !check ?
4465   value && result !== false :
4466   type === "!=" ?

for a "has attribute" selector like "[someattribute]", at this point value="" if the attribute exists but has no value. In this case it should match. If the attribute does not exist, then value=null. This test causes the selector to fail because "" is not truthy.

This code needs to test for an empty string as a valid value when !check is true (meaning we're only testing for existence of an attribute). Here is a proposed correction.

4464   !check ?
4465   (value || value==="") && result !== false :
4466   type === "!=" ?

There are other inconsistencies related to attribute handling at least in IE6 that I have not completely isolated yet. e.g.


causes IE6 to render "disabled" with no value, and other browsers to render disabled="disabled". When testing


IE6 returns "true" and other browsers return "disabled."

This could be a problem with how the attribute is set (versus tested) but I haven't been able to isolate it completely.

Change History (6)

comment:1 Changed 12 years ago by Timmy Willison

Component: unfiledselector
Owner: set to jamietre
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsfiddle.net that reproduces the issue experienced to help us assess your ticket.

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

comment:2 Changed 12 years ago by Timmy Willison

I created this test case to try and reproduce the issue with the disabled attribute and was unable in 1.6 and jQuery (edge).


comment:3 Changed 12 years ago by jamietre

Status: pendingnew

I can't get anything in jsfiddle to run in IE6. Are you actually able to test this fiddle in a browser that doesn't have querySelectorAll support in jsFiddle? If so I'd love some tips because I can't, which is why I've been posting external links.

Here is my very, very simple page showing these two issues:


Please just look at the source to that page. Nothing could be simpler. I include only jQuery and there is nothing else outside the test code. The selector does not work in IE6. Likewise, the "disabled" thing returns different results.

I was able track down the bug by disabling the Sizzle code that uses document.querySelectorAll and forcing it to use it's own implementation no matter what, and debugging in Chrome.

comment:4 Changed 12 years ago by Timmy Willison

Priority: undecidedhigh
Resolution: duplicate
Status: newclosed

I see. Well, this is actually two different issues. It's strange that I am unable to reproduce the behavior your test page shows for the disabled attribute, however when I include the git version of jQuery on your page, it works as expected. Nevertheless, I recommend using prop for getting/setting disabled.

As for the selector bug, that is a duplicate. So since the first has been fixed, I'll direct this ticket to the selector one.

comment:5 Changed 12 years ago by Timmy Willison

Duplicate of #7770.

comment:6 Changed 12 years ago by jamietre

OK, I'm glad the attribute selector bug is being addressed already.

In taking your advice to use the new "prop" instead of "attr" I came across some some problems with that as well, I posted a new bug report http://bugs.jquery.com/ticket/9166

Note: See TracTickets for help on using tickets.