The wrapAll method
The wrapAll method wraps all elements of a set in a single specified tag. If these elements are in different places, jQuery first places them next to each other, and then wraps them in the desired tag.
Syntax
The method parameter can be text (possibly with tags), a DOM element, or a jQuery object:
.wrapAll(what to wrap it with);
We can also use a function for each element:
.wrapAll(function(number in the set))
Example
Let's wrap paragraphs with class www in tag div:
<p class="www">text</p>
<p class="www">text</p>
<p class="www">text</p>
<p>text</p>
$('.www').wrapAll('<div></div>');
HTML the code will look like this:
<div>
<p class="www">text</p>
<p class="www">text</p>
<p class="www">text</p>
</div>
<p>text</p>
See also
-
methods
wrap,wrapInner⁅/ c⁆, ⁅c href="/en/javascript/lib/jquery/manual/unwrap/"⁆unwrap,
allowing you to work with wrapping elements