jQuery wrap()Methods
Examples
Wrap each <p> element in a <div> element:
$("button").click(function(){
$("p").wrap("<div></div>");
});
Try it Yourself »
Definition and Usage
The wrap() method uses the specified HTML element to wrap each selected element.
Syntax
$(selector).wrap(wrappingElement,function(index))
| Parameters | Description |
|---|---|
| wrappingElement | Required. Specifies the HTML element to wrap around each selected element. Possible values:
|
| function(index) | Optional. Specifies a function that returns the wrapping element.
|
More Examples
Create new elements using the DOM
How to use document.createElement() to create elements and use them to wrap each selected element.
Use a function to wrap elements
Use a function to specify what wraps each selected element.
Wrapping and unwrapping elements
How to switch between the tasks of wrapping and unwrapping elements.
Other Extensions
jQuery HTML/CSS Methods