.wrapAll( wrappingElement )Returns: jQuery
Description: Wrap an HTML structure around all elements in the set of matched elements.
-
version added: 1.2.wrapAll( wrappingElement )
-
wrappingElementA selector, element, HTML string, or jQuery object specifying the structure to wrap around the matched elements.
-
-
version added: 1.4.wrapAll( function )
-
functionA callback function returning the HTML content or jQuery object to wrap around all the matched elements. Within the function,
this
refers to the first element in the set. Prior to jQuery 3.0, the callback was incorrectly called for every element in the set and received the index position of the element in the set as an argument.
-
.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.
1
2
3
4
|
|
.wrapAll()
, we can insert an HTML structure around the inner <div>
elements like so:
1
|
|
<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
|
|
Examples:
Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
|
Demo:
Example 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
|
Demo:
Example 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
|
Demo:
Example 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
|