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

jQuery wrapInner() method

jQuery wrapInner() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Insert content after each

Wrap the content of the element in a element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

wrapInner

(

"

"

)

;

}

)

;

Try it »


Definition and Usage

The wrapInner() method wraps all content (innerHTML) inside each selected element with the specified HTML element.


Syntax

$(

selector

).wrapInner(

wrappingElement

,function

(index)

)

Parameters Description
wrappingElement Required. Specifies the HTML element to surround the content of 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 the content of each selected element with it.

    Wrapping content using a function
    Use a function to specify what to wrap the content of each selected element with.


    jQuery HTML/CSS methods jQuery HTML/CSS methods