Bug Tracker

Opened 11 years ago

Closed 11 years ago

#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:
Blocked by: Blocking:

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 (3)

comment:1 Changed 11 years ago by nicluciano

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.

comment:2 Changed 11 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.

comment:3 Changed 11 years ago by john

Resolution: fixed
Status: newclosed

Duplicate of #3873 (already fixed).

Note: See TracTickets for help on using tickets.