gpt4 book ai didi

javascript - 添加一个 Div 标签来环绕 LI 元素

转载 作者:行者123 更新时间:2023-11-30 12:43:23 26 4
gpt4 key购买 nike

我想动态添加一对 Div 标签和一个类来包装 DOM 中的一组元素。我该怎么做呢?

HTML

<div class="right-bottom"> <!-- this is the div tag I would like to add to wrap the content below-->
<li class="">
<a href="">Diffusion Tensor Imaging</a>
<article class="article-body" data-asynchtml-target="">
<div class="loader"></div>
</article>
</li>

</div>

JavaScript

<script type="text/javascript">
var div = document.createElement('div');
</script>

最佳答案

您可以使用 .wrap() 和适当的选择器来定位 li 元素。像这样:

$('.article-body').closest('li').wrap('<div class="right-bottom"></div>')

参见 Documentation .

关于javascript - 添加一个 Div 标签来环绕 LI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23544145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com