如果单击其子元素,则如何获取行的id属性?

Won*_*ger 1 jquery row

如何返回链接所在行的id属性?我尝试了不同的变化,但我能得到的最好的是"未定义"......

html看起来像这样:

<tr id="30">
  <td>Parker</td>
  <td><a href="#" id="id783900" class="section-id">Select</a></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

我试过的一件事是:

$("a.section-id").click(function() {
  var parenttr = $(this).parent().parent().attr("id");
  alert(parenttr);
});
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

$("a.section-id").click(function() {
  var parenttr = $(this).parent('tr').attr("id");
  alert(parenttr);
});
Run Code Online (Sandbox Code Playgroud)

tre*_*ace 6

尝试:

$(this).closest('tr').attr('id');
Run Code Online (Sandbox Code Playgroud)