JQuery wrap() 、wrapAll()、wrapinner()
wrap() 把匹配的元素用指定的内容或元素包裹起来。
wrapAll() 把匹配的元素用指定的内容或元素包裹起来。
wrapinner() 将每一个匹配的元素的内容用指定的内容或元素包裹起来。
例:
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
(1) $("p").wrap("<div></div>");
结果:
<div><p>This is a paragraph.</p></div>
<div><p>This is another paragraph.</p></div>
(2) $("p").wrapAll("<div></div>");
结果: <div>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</div>
(3) $("p").wrapInner("<b></b>");
结果:
<p><b>This is a paragraph.</b></p>
<p><b>This is another paragraph.</b></p>