Getting a parent element for a jquery selector

后端 未结 3 1734
轻奢々
轻奢々 2020-12-10 10:25

I have a table where each row has a CSS id like this:

........         
3条回答
  •  抹茶落季
    2020-12-10 10:30

    Use closest:

    $(".anotherclass").click(function() {
        console.log($(this).closest("tr").attr("id"));
    });
    

    From the docs:

    Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.

提交回复
热议问题