jQuery wrap() method
Example
in
Wrap each element in a
HTML element
jQuery object
DOM element
| | function*(index)* | Optional. Specifies a function that returns the wrapping element.
element:
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
p
"
)
.
wrap
(
"
"
)
;
}
)
;
Try it »
Definition and Usage
The wrap() method wraps each selected element with the specified HTML element.
Syntax
$(
selector
).wrap(
wrappingElement
,function
(index)
)
| Parameters | Description |
|---|---|
| wrappingElement | Required. Specifies the HTML element used to wrap each selected element.
Possible values: |
- index - Returns the index position of the element in the set.
More examples
Creating a new element via the DOM
How to use document.createElement() to create an element and wrap each selected element with it.
Wrapping elements using a function
Use a function to specify what to wrap each selected element with.
Wrapping and unwrapping elements
How to switch between the tasks of wrapping and unwrapping elements.
jQuery HTML/CSS methods