最接近/下一个div选择的jquery

3

我有如下的HTML代码:

<table>
 <tr>
  <td>
    <button class="popup" id="$row[0]"></button>
  </td>
 </tr>
</table>



 <div class="details">
   <div id="section-2">
   </div>
 </div>

以下是jQuery脚本:

    $(document).ready(function() {
      $('.popup').click(function () {
      // something like this : $(this).next(".details").dialog('open');
        $('.details').dialog('open');
        });
      });
    });

我想与类名为details的最接近/下一个div对话。
1个回答

4

details元素是table元素的下一个兄弟元素,因此使用.closest()查找button的表格祖先,然后使用.next()查找details元素。

$(document).ready(function () {
    $('.popup').click(function () {
        // something like this : $(this).next(".details").dialog('open');
        $(this).closest('table').next('.details').dialog('open');
    });
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接