.wrapInner( wrappingElement )Returns: jQuery
Description: Wrap an HTML structure around the content of each element in the set of matched elements.
-
version added: 1.2.wrapInner( wrappingElement )
-
wrappingElementAn HTML snippet, selector expression, jQuery object, or DOM element specifying the structure to wrap around the content of the matched elements.
-
-
version added: 1.4.wrapInner( function )
-
functionA callback function which generates a structure to wrap around the content of the matched elements. Receives the index position of the element in the set as an argument. Within the function,
this
refers to the current element in the set.
-
.wrapInner()
function can take any string or object that could be passed to the $()
factory 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 the content of each of the elements in the set of matched elements.
1
2
3
4
|
|
.wrapInner()
, we can insert an HTML structure around the content of each 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 the content of each matched element:
1
2
3
4
5
6
7
8
|
|
1
2
3
|
|
<div>
to have a class corresponding to the text it wraps:
1
2
3
4
5
6
7
8
|
|
.wrapInner()
function, the expected input is well formed HTML with correctly closed tags. Examples of valid input include:
1
2
|
|
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
|
|
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
|
|
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
|
|
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
|
|