Bug Tracker

Ticket #9156 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 Changed 4 years ago by jamietre

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.

comment:2 Changed 4 years ago by timmywil

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to selector

Thanks for looking into it.

comment:3 Changed 4 years ago by jamietre

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/

Note: See TracTickets for help on using tickets.