Bug Tracker

Opened 10 years ago

Closed 9 years ago

#4873 closed bug (patchwelcome)

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)

empty_anchor_attribute_selector.htm (1.2 KB) - added by mqj 10 years ago.
Compares selecting anchors and inputs with empty hrefs and values.

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by mqj

Compares selecting anchors and inputs with empty hrefs and values.

comment:1 Changed 9 years ago by dmethvin

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.

comment:2 Changed 9 years ago by danheberden

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

Note: See TracTickets for help on using tickets.