我需要用一个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中。
发布于 2009-10-14 15:38:08
你试过这个吗?
$('div.someClass p').wrapAll(...);还是这个?
$('div.someClass').each(function() {
$(this).find('p').wrapAll(...);
});编辑
在查看了您发布的代码之后,它似乎是一个语法问题。您需要这一行的引号:
$(this).find('p').wrapAll(<div class='toggle'></div>);它应该是:
$(this).find('p').wrapAll("<div class='toggle'></div>");https://stackoverflow.com/questions/1567121
复制相似问题