gpt4 book ai didi

javascript - jQuery 选择标签组

转载 作者:行者123 更新时间:2023-11-30 10:04:06 25 4
gpt4 key购买 nike

假设我有这个结构:

<p>Some text random 1</p>
<p>Some text random 2</p>
<p>Some text random 3</p>
<div><img src=""></div>
<p>Some text random 4</p>
<p>Some text random 5</p>

我想在一个 div 元素中包围 p 标签组,有谁知道最好的方法吗?首选输出是:

<div class="p-tags">
<p>Some text random 1</p>
<p>Some text random 2</p>
<p>Some text random 3</p>
</div>
<div><img src=""></div>
<div class="p-tags">
<p>Some text random 4</p>
<p>Some text random 5</p>
</div>

最佳答案

你可以使用wrapAll

$("p").slice(0,3).wrapAll('<div class="p-tags"></div>');
$("p").slice(3,5).wrapAll('<div class="p-tags"></div>');

DEMO

关于javascript - jQuery 选择标签组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30190169/

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