How To Select First Ancestor That Matches A Selector?

后端 未结 4 1319
佛祖请我去吃肉
佛祖请我去吃肉 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:38

    Assuming you're using jQuery 1.4, you can use .parentsUntil() which will return all of the ancestors upto but NOT including the selected ancestor.

    So in your case I would go with something like this:

    $('.remove').click(function(){
        $(this).parentsUntil("tr").parent().hide();
        return false;
    });
    

提交回复
热议问题