English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The wrap() method will wrap each selected element with the specified HTML element.
Useunwrap()Method to remove the parent element of the selected element.
Wrapper element:
$.wrap(wrappingElement)
Wrap elements using a function:
$.wrap(function(index))
Wrap the DIV element around each <p> element:
$("button").click(function(){ $("p").wrap("<div></div>"); });Test to see‹/›
This example uses document.createElement() to create a DIV element and wrap it around each <p> element:
$("button").click(function(){ $("p").wrap(document.createElement("div")); });Test to see‹/›
Wrap elements using a function:
$("button").click(function(){ $("p").wrap(function(){ return document.createElement("div"); }); });Test to see‹/›
Toggle between wrapping and unwrapping elements:
$("#btn1").click(function(){ $("p").wrap("<div></div>"); }); $("#btn2").click(function(){ $("p").unwrap(); });Test to see‹/›
Parameter | Description |
---|---|
wrappingElement | Specify the structure to wrap each selected element Possible Values:
|
function(index) | Specify a function that returns the wrapping element
|