Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 12 years ago

#4798 closed bug (worksforme)

Selecting descendants of something:last yields duplicates

Reported by: Catrope Owned by: john
Priority: major Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: :last descendants Cc:
Blocked by: Blocking:


I have a document with two <table> with class="toc", each containing a nested <ul> with a bunch of <li>s. $('.toc * li') will return all <li> elements as expected. $('.toc:last * li') returns all <li> elements in the last table, as expected, but returns each <li> four times. This means, among other things, that $('.toc:last * li').each(someFunction); calls someFunction() four times for every <li>. Example attached.

Attachments (1)

test.html (573 bytes) - added by Catrope 14 years ago.
Test case

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by Catrope

Attachment: test.html added

Test case

comment:1 Changed 14 years ago by dmethvin

Component: unfilledselector
Owner: set to john

comment:2 Changed 12 years ago by addyosmani

Keywords: :last descendants added
Resolution: worksforme
Status: newclosed

I have recreated your test case here Live Test Case, however using jQuery 1.4.3 this appears to be working fine now.

comment:3 in reply to:  2 Changed 12 years ago by jitter

Replying to addyosmani:

however using jQuery 1.4.3 this appears to be working fine now.

What do you mean by that? Your test case shows the exact behavior Catrope reported. Using Opera 10.62 I get 12 alerts when opening your test saying "One/Two/Three-B" 4 times. Instead of only getting 3 alerts (one for each li).

Another test case. For every jQuery version > 1.2.6 the result of $('.toc * li').length is different from $('.toc:last * li').length although there is only one .toc element in my test case and thus the results should be the same.

$('.toc * li').length correctly returns the same as $('.toc li').length (3 for my test)

But $('.toc:last * li').length returns the #non-li-descendants of .toc X #of li-descendants of toc (12 instead of 3).

Version 0, edited 12 years ago by jitter (next)
Note: See TracTickets for help on using tickets.