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 comment:1
Changed May 06, 2011 10:12PM UTC by comment:2
component: | unfiled → selector |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
Thanks for looking into it.
Changed May 06, 2011 10:26PM UTC by 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:
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.