If I have deep nested unordered list and I have a reference to the root node, is there a built in way to find a last child of "li" type that has specific css class? For example if I have a tree view branch 5 levels deep, and branch is expanded down to thrid level, levels 1,2,3 will have a class "collapsable". Now I want to find a last "li" in this case on level 3 that has this class.
Asked
Active
Viewed 9,051 times
1 Answers
13
Not too hard:
$("li.someclass", rootOfList).last()
searches rootOfList
for the last li
with class someclass

Dan
- 10,990
- 7
- 51
- 80
-
1Yes. If you're using 1.3 you can use $("li.someclass:last", rootOfList) instead. – Per H Jan 21 '10 at 21:40
-
how about this solution ... https://stackoverflow.com/a/10539199/4425004 – Pranesh Janarthanan Mar 14 '19 at 06:57