Moving up multiple parents in jQuery - more efficient way?

前端 未结 6 515
庸人自扰
庸人自扰 2021-01-04 03:06

So, I have a navigation that is a list and has sublists and sublists.

Basically, the nav is by default collapsed, but if people click on a page that\'s in a sublist,

6条回答
  •  被撕碎了的回忆
    2021-01-04 03:12

    $(this).closest("ul") will traverse the parents until it finds a ul

    http://docs.jquery.com/Traversing/closest#expr

    ...get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree...

提交回复
热议问题