Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: find a last child that has specific class

Tags:

jquery

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.

like image 247
epitka Avatar asked Jan 21 '10 21:01

epitka


1 Answers

Not too hard:

$("li.someclass", rootOfList).last()

searches rootOfList for the last li with class someclass

like image 51
Dan Avatar answered Nov 10 '22 18:11

Dan