Bug Tracker

Modify

Ticket #4798 (closed bug: worksforme)

Opened 4 years ago

Last modified 3 years ago

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

Description

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

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

Change History

Changed 4 years ago by Catrope

Test case

comment:1 Changed 4 years ago by dmethvin

  • Owner set to john
  • Component changed from unfilled to selector

comment:2 follow-up: ↓ 3 Changed 3 years ago by addyosmani

  • Keywords :last descendants added
  • Status changed from new to closed
  • Resolution set to worksforme

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 3 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).,

This seems to happen no matter what PSEUDO selector your use in the selector

Last edited 3 years ago by jitter (previous) (diff)

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.