I have a table where each row has a CSS id like this:
...
...
..
相关标签:
-
2020-12-10 10:27
you can use this.
$('.anotherclass').click(function () {
alert($(this).parents('tr').attr("id"));
});
-
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.
-
2020-12-10 10:39
Use closest():
$('.anotherclass').click(function () {
alert($(this).closest('tr').prop('id'));
});