jQuery wrapInner() Method

The jQuery wrapInner() method can be used to wrap the inner content of selected elements with the wrapping element. You have to specify the HTML wrapping element to wrap around the content of the elements.

jQuery wrapInner() Method

Syntax

The syntax of this method is given below:-

Syntax
$(selector).wrapInner(htmlwrappingElement, function(index))

Description of the Parameters

The above syntax contains two parameters to use the method. The description of these parameters is given below.

Parameter Name Description
selector Specify the element to wrap the inner content using the method. You have to use tag name, class name, or id of the elements to select. It is a required field.
htmlwrappingElement It is the HTML element to wrap around the inner content of the elements. It is a required field.

jQuery wrapInner() Method to Wrap Inner Content of an Element

If you want to wrap the inner content of the selected element, you have to use this method. The below example contains 2 paragraphs with content. The method wraps the inner content of the paragraph.

Example

Test it Live

Output

First paragraph.

Second paragraph.


You have to click the button given above to wrap the content of the element. The element wrapped with the HTML em element to make it italic.

Using Function Wrap Inner Content

You can also use the function to wrap the inner content of the selected element. Use the jQuery wrapInner() method as given in the example below.

Example

Test it Live

Output

This is my paragraph.


When you click the button above, it makes the content small using the HTML sup element. The selected element got wrapped with the specified HTML element using the function.

You may also like to read

I hope you like this tutorial on jQuery wrapInner() method. If you have any queries regarding the tutorial, please comment below.

References