English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery wrapInner() Method

jQuery HTML/CSS Methods

The wrapInner() method wraps the specified HTML element around the content of each selected element.

Syntax:

Wrap an element around the content:

$(selector).wrapInner(wrappingElement)

Wrap an element around the content using a function:

$(selector).wrapInner(function(index))

Example

Wrap the <b>element around the content of each <p>element:

$("button").click(function(){
  $("p").wrapInner("<b></b>");
});
Test See‹/›

This example uses document.createElement() to create a <b> element and wrap it around the content of each <p> element:

$("button").click(function(){
  $("p").wrapInner(document.createElement("b"));
});
Test See‹/›

Use a function to wrap content:

$("button").click(function(){
  $("p").wrapInner(function(){
      return document.createElement("b");
  });
});
Test See‹/›

Parameter Values

ParametersDescription
wrappingElementSpecify the HTML element that wraps around the content of each selected element.

Possible Values:

  • HTML Element

  • DOM Element

  • jQuery Object

function(index)Specify a function that returns the wrapping element
  • index-Return the index position of the element in the collection

jQuery HTML/CSS Methods