Ticket #9156 (closed bug: invalid)
Has attribute selector not working in IE6-9
|Reported by:||jamietre||Owned by:|
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>
<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.