Latest web development tutorials

jQuery wrap () method

jQuery HTML / CSS Methods jQuery HTML / CSS Methods

Examples

Wrap each <p> element in the <div> element:

$("button").click(function(){
$("p").wrap("<div></div>");
});

try it"

Definition and Usage

wrap () method using the specified HTML element to wrap each selected element.


grammar

$(selector).wrap(wrappingElement,function(index))

参数 描述
wrappingElement 必需。规定包裹每个被选元素的 HTML 元素。

可能的值:

  • HTML 元素
  • jQuery 对象
  • DOM 元素
function (index) 可选。规定返回包裹元素的函数。
  • index- 返回集合中元素的 index 位置。


Examples

More examples

Create new elements by DOM
How to use document.createElement () to create the element, and use it to wrap each selected element.

Use the function element package
Use what function requires that each package selected elements.

Parcels and unlock elements
How to unlock the elements between packages and task switching.


jQuery HTML / CSS Methods jQuery HTML / CSS Methods