jQuery wrap()Methods

jQuery HTML/CSS 方法jQuery HTML/CSS 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:

  • HTML elements
  • jQuery object
  • DOM element
function(index) Optional. Specifies a function that returns the wrapping element.
  • index- Returns the index position of the element in the set.


实例

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.


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions