How To Select First Ancestor That Matches A Selector?

后端 未结 4 1310
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 08:11

General:

How can I select the first matching ancestor of an element in jQuery?

Example:

Take this HTML block

<
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 08:20

    I prefer using closest as @Kobi points out (+1) as it seems to be the most concise way to do that. Just to point out, you can also use parents:

    $(this).parents("tr:first")
    

提交回复
热议问题