Skip to main content

Bug Tracker

Side navigation

#4873 closed bug (patchwelcome)

Opened July 09, 2009 03:19PM UTC

Closed March 31, 2011 04:25AM UTC

Empty Anchor Attribute Selector

Reported by: mqj Owned by: john
Priority: major Milestone: 1.next
Component: selector Version: 1.3.2
Keywords: anchor empty attribute Cc:
Blocked by: Blocking:
Description

See also tickets #3933 and #3990.

Ticket #3990 which attempts to select input elements with empty or null values and is fixed.

Attempts to select anchor elements will empty or null values and is not fixed.

Test cases (http://dev.jquery.com/changeset/6181) indicate only an option element was used. If an anchor element with an empty href attribute would be added to the test case, would it pass as well?

<a href="/">anchor with an href to /</a>

<a>anchor with no href</a>

<a href="">anchor with explicit empty string href</a>

Selecting anchors with blank hrefs.

jQuery("a[href=]").length jQuery 1.2.6 returns 2

jQuery("a[href=]").length jQuery 1.3 returns 1

jQuery("a[href=]").length jQuery 1.3.1 returns 1

jQuery("a[href=]").length jQuery 1.3.2 returns 1

Selecting anchors with non-blank hrefs.

jQuery("a[href!=]").length jQuery 1.2.6 returns 1

jQuery("a[href!=]").length jQuery 1.3 returns 1

jQuery("a[href!=]").length jQuery 1.3.1 returns 2

jQuery("a[href!=]").length jQuery 1.3.2 returns 2

jQuery 1.2.6 is the last version that contains desired behaviour when selecting anchor elements with blank and non-blank hrefs.

Attachments (1)
Change History (2)

Changed November 17, 2010 04:46AM UTC by dmethvin comment:1

milestone: 1.4
status: newopen

http://jsfiddle.net/dmethvin/Ke9ut/

IE is no doubt making the href="" case non-empty by turning it into an absolute url, but .attr("href") seems to be correct.

The selectors should have '' for an empty string to be valid.

Changed March 31, 2011 04:25AM UTC by danheberden comment:2

milestone: → 1.next
resolution: → patchwelcome
status: openclosed

IE6 and IE7 store attributes differently than other browsers. Instead of an array of attributes, there are specific keys. So element.attributes.href is always there - and if you've specified an href, element.attributes.href.specified is true. But IE will still expand it, so there is no way to tell if you put http://yourdomain.com/ as the url or "" - they get expanded to the same thing.

In the end, we're forced to compare the href - which doesn't help with empty strings :( Definitely one of those shake your fist at IE moments :p