如何在 jQuery 中使用 .wrapAll() ?
我需要找到所有 div
中具有 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()
时:对于每个具有 someClass
类的 div
,包装所有 p
标签,但它只是将它们全部包装在顶部 div
中。
I need to find all the p tags inside all the div
s with a class of someClass
and wrap them with another div
. This is how the beginning mark up would look like:
<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>
Would turn into:
<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>
Any ideas? When I try using .each()
: for each div
with a class of someClass
wrap all the p
tags, but it just wraps them all together in the top div
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过这个吗?
还是这个?
编辑
查看您发布的代码后,这似乎是一个语法问题。您需要在这一行中加上引号:
它应该是:
Have you tried this?
Or this?
Edit
After looking at the code you posted, it appears to be a syntax issue. You need quotes in this line:
It should be: