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

jQuery wrapAll() Method

jQuery HTML/CSS Methods

The wrapAll() method wraps the specified HTML element around all selected elements.

Syntax:

$.wrapAll(wrappingElement)

Example

Wrap the DIV element around all <p> elements:

$("button").click(function(){
  $("p").wrapAll("<div></div>");
});
Test and See‹/›

This example uses document.createElement() to create a DIV element and wrap it around all <p> elements:

$("button").click(function(){
  $("p").wrapAll(document.createElement("div"));
});
Test and See‹/›

Note that in this example, all the content between paragraphs is forgotten, for example (About me?):

This is the first paragraph.

This is the second paragraph.

What about me?

This is the last paragraph.

Run the code

The difference between the wrap() method and the wrapAll() method:

$("#btn1").click(function(){
  $("p").wrap("<div></div>");
});
$("#btn2").click(function(){
  $("p").wrapAll("<div></div>");
});
Test and See‹/›

Parameter Value

ParameterDescription
wrappingElementSpecify the structure to wrap all selected elements

Possible Values:

  • HTML Element

  • DOM Element

  • jQuery Object

jQuery HTML/CSS Methods