查找一个类并将其添加到另一个元素

发布于 2024-09-27 16:20:55 字数 446 浏览 0 评论 0原文

我需要找到一种方法从 li 获取类,然后将该类添加到包含我所有主要内容的 div 中。所以...




  <div class="cntrWrap LI_CLASS_GOES_HERE">
    HTML TEXT GOES HERE
  </div>

有人可以帮忙吗?我尝试了很多不同的想法,但我对 jQuery 仍然很陌生。

I need to find a way to the get the class from a li and then add that class to a div that wraps all my main content. so...

<div class="structBody">
<ul id="ContentBreadCrumbsColor">
<li class="teal"></li>
</ul>

  <div class="cntrWrap LI_CLASS_GOES_HERE">
    HTML TEXT GOES HERE
  </div>

</div>

Can anyone help? I have tried so many different ideas but I'm still very new to jQuery.

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

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

发布评论

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

评论(1

几度春秋 2024-10-04 16:20:56

这应该可以做到。

$(document).ready(function()
        {
            $('div.structBody').addClass($('li.teal').attr('class'));
        }
);

如果您还没有阅读过jQuery 官方网站文档,我会推荐它。

This should do it.

$(document).ready(function()
        {
            $('div.structBody').addClass($('li.teal').attr('class'));
        }
);

I'd recommend the official jQuery website's documentation, if you haven't already gone through it.

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