Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery wrap() method

jQuery wrap() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

in

Wrap each element in a

element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

wrap

(

"

"

)

;

}

)

;

Try it »


Definition and Usage

The wrap() method wraps each selected element with the specified HTML element.


Syntax

$(

selector

).wrap(

wrappingElement

,function

(index)

)

Parameters Description
wrappingElement Required. Specifies the HTML element used to wrap each selected element.

Possible values:

  • HTML element
  • 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

    Creating a new element via the DOM
    How to use document.createElement() to create an element and wrap each selected element with it.

    Wrapping elements using a function
    Use a function to specify what to wrap each selected element with.

    Wrapping and unwrapping elements
    How to switch between the tasks of wrapping and unwrapping elements.


    jQuery HTML/CSS methods jQuery HTML/CSS methods