How do I get the n-th level parent of an element in jQuery?

后端 未结 13 1975
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 10:24

When I want to get, for example, the 3rd level parent of the element I must write $(\'#element\').parent().parent().parent() Is there a more optimal method for

13条回答
  •  攒了一身酷
    2020-12-12 11:14

    using eq appears to grab the dynamic DOM whereas using .parent().parent() appears to grab the DOM that was initially loaded (if that is even possible).

    I use them both on an element that has classes applied it to on onmouseover. eq shows the classes while .parent().parent() doesnt.

提交回复
热议问题