jQuery wrapAll() Method

The jQuery wrapAll() method can be used to wrap all the selected elements with the specified HTML wrapping element. You have to specify the HTML wrapping element to wrap around all the selected elements.

jQuery wrapAll() Method

Syntax

The syntax of this method is given below:-

Wrap All Selected Element
$(selector).wrapAll(htmlwrappingElement)

Description of the Parameters

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

Parameter Name Description
selector Specify the element to select and wrap using the method. Use tag name, class name, or id of the elements to select. It is a required field.
htmlwrappingElement You have to Specify the HTML element to wrap all the selected elements. It is a required field.

jQuery wrapAll() Method to Wrap All Selected Element

If you want to wrap all the selected elements within the specified wrapping HTML element. You can use this method as given in the example below.

The example contains 3 paragraphs element to wrap. The jQuery wrapAll() method wraps all these paragraphs with the specified wrapping div element. The example uses the click event to wrap the element on button click.

Example

Test it Live

Output

First paragraph.

Second paragraph.

Third paragraph.


When you click the button given above, the wrapping element wraps all the selected paragraph element with the div element. The div element contains some CSS property which automatically gets added on wrapping.

The above example using the click event to wrap the element. When you click the button given above, the div element got wrapped around the paragraph element.

You may also like to read

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

References