我正在尝试使用 jQuery wrapAll 将一个 h1
标签和多个 p
标签包装到一个 div
中。
这是我的 HTML:
<h1>Title</h1>
<p>This is a paragraph</p>
<p>This is another paragraph</p>
<div class="img"></div>
还有我的 jQuery:
$('h1').wrapAll('<div class="first-col" />');
$('.img').wrapAll('<div class="second-col" />');
还有一个 JSFIDDLE .
目前,我只能环绕h1
标签,或者分别环绕h1
和p
标签。我希望它们都在一个 first-col
div 中。
有人知道怎么做吗?
最佳答案
关于javascript - 使用 wrapAll 选择不同的元素 — jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18511064/