Ticket #9424 (closed bug: duplicate)
filter('[href]') fails to match links with empty href attrs in some cases
| Reported by: | nonsensery | Owned by: | nonsensery |
|---|---|---|---|
| Priority: | high | Milestone: | 1.next |
| Component: | selector | Version: | 1.6 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
(This is similar to #4873, but not the same. In this case, the selector correctly matches these elements in some cases, but not in others)
Environment: This bug occurs in jQuery 1.2 - 1.6, but the failures are different in 1.2 and 1.3. I would guess that it also affects jQuery 1.6.1, but that version is unavailable for testing. Verified in Mac Chrome 11, Firefox 4, Safari 5; IE 9.
Please see this test case: http://jsfiddle.net/Zh7ME/2/
In jQuery 1.4 - 1.6, when using the filter() method, the selector [href] fails to match a link with an href attribute with an empty value, e.g. <a href="">example link</a>, but only if there are other elements in the set. If there is a single element, filter() works correctly. Also, it appears that the selector works correctly when passed to the jQuery function itself, like: $('a[href]').
In earlier versions of jQuery (1.2 - 1.3), and in older versions of IE (7 - 8) there are different failures. You can change the jQuery version in the test case to see those failures, but (personally) I am not concerned with these environments.
To summarize, the problem is not that the selector does not work, but rather that it behaves differently under different circumstances.
Change History
comment:1 Changed 2 years ago by rwaldron
- Owner set to nonsensery
- Status changed from new to pending
- Component changed from unfiled to selector
comment:2 Changed 2 years ago by nonsensery
- Status changed from pending to new
The test case above is fairly complicated because the characteristics of this bug are complex, but here is a more simple example that illustrates one aspect of it: http://jsfiddle.net/2KH7c/
Hope that helps,
Alex
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Could you possibly reduce that test case? Instead of outputting html results, try using console.log() :D
Thanks!