【发布时间】:2010-12-06 17:32:05
【问题描述】:
我需要在所有divs 中找到所有带有someClass 类的p 标签,并用另一个div 包装它们。这是开始标记的样子:
<div class="someClass">
// Lots of different tags generated by the site
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
</div>
<div class="someClass">
// Lots of different tags generated by the site
<p>Some text</p>
<p>Some text</p>
</div>
会变成:
<div class="someClass">
// Lots of different tags generated by the site
<div class="bla">
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="someClass">
// Lots of different tags generated by the site
<div class="bla">
<p>Some text</p>
<p>Some text</p>
</div>
</div>
有什么想法吗?当我尝试使用.each(): 对于每个div 和someClass 类时,包装所有p 标签,但它只是将它们全部包装在顶部div。
【问题讨论】:
-
你能发布你的代码吗?你的方法听起来不错。
-
我在这里发布了一个示例:pastebin.me/30acb260acc142dd0c9979aca9812390
标签: javascript jquery for-loop each wrapall