jquery - 如何获取div内的html

发布于 2024-09-06 14:11:30 字数 609 浏览 2 评论 0原文

我有这个 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>

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

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

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

谢谢

I have this 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>

how do i get the html after i click the button at the portlet-header part, in this case, the table tag?

I have this jquery code to get the text on the header: $(this).parent().text(); but got nowhere in trying to retrieve the html under the "content_regular" class as shown above.

Hope your wisdom can help me with this. i know this very easy to others but i am not familiar with jquery.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盛装女皇 2024-09-13 14:11:30

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

$(".portlet-header").click(function() {
  var html = $(this).next(".portlet-content").html();
});

如果 div、另一个元素等之间可能存在某些内容,请使用 .nextAll () 而是这样:.nextAll(".portlet-content:first")

Use .next() to get from .portlet-header to .portlet-content then use .html() rather than .text() to get the content, like this:

$(".portlet-header").click(function() {
  var html = $(this).next(".portlet-content").html();
});

If there may be something between the divs, another element, etc, use .nextAll() instead, like this: .nextAll(".portlet-content:first")

心碎无痕… 2024-09-13 14:11:30
$('.portlet-header button').click(function(){
   alert($('.content_regular').html())
});

不错的读物

  1. .html()
  2. jQuery 选择器
  3. 遍历

这是一个演示

$('.portlet-header button').click(function(){
   alert($('.content_regular').html())
});

nice readings

  1. .html()
  2. jQuery selectors
  3. Traversing

here is a demo

ζ澈沫 2024-09-13 14:11:30

首先,使用 html() 函数而不是 text() 函数。其次,将选择器指向正确的节点,例如 .portlet-content .content_regular table。我会让你自己将这两者结合起来。

First, use the html() function instead of the text() function. Second, point your selector to the right node, something like .portlet-content .content_regular table. I'll let you do the combining of these two yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文