Skip to main content

Bug Tracker

Side navigation

#4798 closed bug (worksforme)

Opened June 21, 2009 06:01PM UTC

Closed October 29, 2010 06:11AM UTC

Last modified October 29, 2010 06:22PM UTC

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:
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 (1)
  • test.html (0.6 KB) - added by Catrope June 21, 2009 06:02PM UTC.

    Test case

Change History (3)

Changed June 23, 2009 01:30AM UTC by dmethvin comment:1

component: unfilledselector
owner: → john

Changed October 29, 2010 06:11AM UTC by addyosmani comment:2

keywords: → :last descendants
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.

Changed October 29, 2010 06:22PM UTC by jitter comment:3

_comment0: Replying to [comment:2 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 [http://jsfiddle.net/jitter/LakZC/ 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).1288376604257703

Replying to [comment:2 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