Skip to main content

Bug Tracker

Side navigation

#9156 closed bug (invalid)

Opened May 06, 2011 09:52PM UTC

Closed May 06, 2011 10:12PM UTC

Last modified May 06, 2011 10:26PM UTC

Has attribute selector not working in IE6-9

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

Test: http://www.outsharked.com/ie_attr.html

The "has attribute" selector: http://api.jquery.com/has-attribute-selector/ for DOM elements with an attribute having no value, or having a missing value, e.g.

<div id="somediv" datafield ></div>

or

<div id="somediv" datafield=""></div>

is not detected in IE6-9

$("[datafield]").length = 0 in IE

$("[datafield]").length = 1 in FF/Chrome

This is a workaround, sort of - it can be used when the attribute is known to be empty. I do not know of any consistent way to detect the existence of an attribute that could or could not have a value because of this bug.

$("[datafield=' ']").length = 1 in all browsers (when datafield has no value or empty value)

(there's not really a space in there. i just couldn't figure out how to get this wikiformatting to render two single quotes in a row)

If there is a non-empty value the behavior is correct across all browsers.

Attachments (0)
Change History (3)

Changed May 06, 2011 10:03PM UTC by jamietre comment:1

Argh! My mistake.

There is an inconsistency in the behavior, but my HTML close tag is in the wrong place, so the error is irrelevant. Please close.

Changed May 06, 2011 10:12PM UTC by timmywil comment:2

component: unfiledselector
priority: undecidedlow
resolution: → invalid
status: newclosed

Thanks for looking into it.

Changed May 06, 2011 10:26PM UTC by jamietre comment:3

Argh! There is still an issue. I did have a markup problem, which *appeared* to correct things. But that was only in jsFiddle. I'm still getting inconsistent behavior in IE6 in a standalone page.

I can't reproduce in on jsfiddle. This problem first came up while trying to do unit tests (in a very simple HTML construct) on IE, so maybe the simplicity of the wrapper has something to do with it.

I don't see anything wrong with my HTML (now) at the original link I posted:

http://www.outsharked.com/ie_attr.html

and it is still not detecting the attributes in IE6-9.

A fiddle with exactly the same markup/code that does not show the problem is here:

http://jsfiddle.net/E86wC/3/