Ticket #3903 (closed bug: fixed)
:first selector selects all elements
| Reported by: | Uzbekjon | Owned by: | john |
|---|---|---|---|
| Priority: | major | Milestone: | 1.3.1 |
| Component: | selector | Version: | 1.3 |
| Keywords: | :first, selector | Cc: | |
| Blocking: | Blocked by: |
Description
Trying to remove first anchor in the following list removes all of them:
<div id="container">
<ul id="menu">
<li><a href="#">Home</a></li> <li><a href="#">Rules</a></li> <li><a href="#">Pilots</a></li> <li><a href="#">Briefing</a></li> <li><a href="#">IGC</a></li> <li><a href="#">Results</a></li> <li><a href="#">Forum</a></li>
</ul>
</div>
Removes all anchors. $('#menu li a:first').remove();
Change History
comment:2 Changed 4 years ago by kswedberg
Actually, it may be a bug, at least in the sense that the results are different from those of any prior jQuery version. It isn't just about :first, though. It has to do with multiple-descendant selectors in general. I've provided a test case at http://test.learningjquery.com/selector-bug.html with side-by-side comparison of 1.2.6 and 1.3, showing the number of matches.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

This is not a bug, as the selector is looking for the first anchor element within every list item. "#menu li:first a" is the correct selector.