如何在表行的另一个单元格中按类名查找元素?

时间:2009-09-17 21:11:13

标签: jquery

从td中文本框的更改事件中,我想找到一个div,其classname ='licenseStatus'位于文本框所在行的另一个单元格中,但似乎无法弄明白... < / p>

$('#gridRequestedApps .xxxAppName').change(function() {
   var licenseOutputCell = $(this).parent('tr').find(".licenseStatus");
   alert(licenseOutputCell.text());    // is an empty string
});

1 个答案:

答案 0 :(得分:1)

您可能需要使用parents()功能:

$("#gridRequestedApps .xxxAppName").change
(
  function()
  {
    var licenseOutputCell = $(this)
                              .parents("tr:first")
                              .find("div.licenseStatus");
    alert(licenseOutputCell.text());
  }
);

parents("tr:first")有效,因为您选择的是第一个TR祖先元素,而不是parent()所做的直接父级。