jQuery .wrapAll()
Learn all about the jQuery function .wrapAll().
The .wrapAll()
function can take any string or object that could be passed to the $()
function to specify a DOM structure. This structure may be nested several levels deep, but should contain only one inmost element. The structure will be wrapped around all of the elements in the set of matched elements, as a single group.
Consider the following HTML:
1
2
3
4
|
|
Using .wrapAll()
, we can insert an HTML structure around the inner <div>
elements like so:
1
|
|
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:
1
2
3
4
5
6
|
|