Ticket #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: | |
| Blocking: | Blocked by: |
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
Change History
Changed 4 years ago by mqj
-
attachment
empty_anchor_attribute_selector.htm
added
comment:1 Changed 3 years ago by dmethvin
- Status changed from new to open
- Milestone 1.4 deleted
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 2 years ago by danheberden
- Status changed from open to closed
- Resolution set to patchwelcome
- Milestone set to 1.next
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Compares selecting anchors and inputs with empty hrefs and values.