jQuery Document Manipulation - wrap() Method
Example
Wrap each paragraph inside a <div> element:
$(".btn1").click(function(){ $("p").wrap("<div></div>"); });
Definition and Usage
The wrap() method places each selected element inside the specified HTML content or element.
Syntax
$().wrap(wrapper)
Parameters | Description |
---|---|
wrapper |
Required. Specifies the content to wrap around the selected elements. Possible values:
Existing elements will not be moved, only copied and wrapped around the selected elements. |
Use a function to wrap elements
Use a function to specify the content wrapped around each selected element.
Syntax
$().wrap(function())
Parameters | Description |
---|---|
function() | Required. Specifies the function that returns the wrapping element. |
More examples
- Use the new element to wrap
- Create a new DOM element to wrap each selected element.
- Wrap or unwrap elements
- Toggle between wrapping and unwrapping elements.