A jQuery method that wraps an HTML structure around all elements in the set of matched elements.
.wrapAll()
is a jQuery method. It is used to:
wrap an HTML structure around all elements in the set of matched elements
— api.jquery.com
Consider the following HTML:
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
Using .wrapAll()
, we can insert an HTML structure around the inner <div>
elements like so:
$( ".inner" ).wrapAll( "<div class='new' />");
The new <div>
element is created on the fly and added to the DOM. The result is a new <div>
wrapped around all matched elements:
<div class="container">
<div class="new">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
</div>