Skip to main content

Bug Tracker

Side navigation

#3903 closed bug (fixed)

Opened January 17, 2009 07:32PM UTC

Closed January 17, 2009 10:37PM UTC

: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();

Attachments (0)
Change History (3)

Changed January 17, 2009 08:34PM UTC by nicluciano comment:1

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.

Changed January 17, 2009 08:47PM UTC by kswedberg comment:2

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.

Changed January 17, 2009 10:37PM UTC by john comment:3

resolution: → fixed
status: newclosed

Duplicate of #3873 (already fixed).