jquery - 如何获取div内的html

mar*_*ela 4 jquery traversal

我有这个html:

<div class="portlet-header">
    Company Information ... <button> some button here </button>
</div>
<div class="portlet-content">
    <div class="content_regular">
        <table style=" width:100%; height:100%;">
            ...content
        </table>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

单击 portlet-header 部分的按钮(在本例中为 table 标记)后,如何获取 html?

我有这个 jquery 代码来获取标题上的文本:$(this).parent().text();但在尝试检索“content_regular”类下的 html 时却无处可去,如上所示。

希望你的智慧能帮助我解决这个问题。我知道这对其他人来说很容易,但我不熟悉jquery。

谢谢

Nic*_*ver 5

使用.next()to 获取内容.portlet-header,然后.portlet-content使用.html()而不是.text()获取内容,如下所示:

$(".portlet-header").click(function() {
  var html = $(this).next(".portlet-content").html();
});
Run Code Online (Sandbox Code Playgroud)

如果 div、另一个元素等之间可能存在某些内容,请.nextAll()改为使用,如下所示:.nextAll(".portlet-content:first")