jQuery parent of a parent

前端 未结 9 1474
执笔经年
执笔经年 2020-12-02 05:40

I am currently trying to find the parent of a parent of an element. I have a link being clicked that is in a , and I\'d like to get the

相关标签:
9条回答
  • 2020-12-02 06:29

    This snippet has performed for me in the past:

    $(this).parent().parent(); 
    

    Post some code for us to see if there might be another problem somewhere...

    0 讨论(0)
  • 2020-12-02 06:30

    The best way would probably be using closest:

    $(this).closest('tr');
    

    Check out the documentation:

    Closest works by first looking at the current element to see if it matches the specified expression, if so it just returns the element itself. If it doesn't match then it will continue to traverse up the document, parent by parent, until an element is found that matches the specified expression. If no matching element is found then none will be returned.

    0 讨论(0)
  • 2020-12-02 06:30

    That should work... you might try

    $(this).parents(':eq(1)');
    

    The .parents(selector) says get all ancestors that match the selector

    and the :eq(1) says find the oneth (zero-indexed, so the second) element in the list

    0 讨论(0)
提交回复
热议问题