jQuery Document Manipulation - wrapAll() Method

Example

Wrap all paragraphs inside <div>:

$(".btn1").click(function(){
   $("p").wrapAll("<div></div>");
});

Try it yourself

Definition and Usage

wrapAll() places all selected elements in the specified HTML content or element.

Syntax

$().wrapAll(wrapper)
Parameter Description
wrapper

Required. Specifies the content to wrap around the selected elements.

Possible values:

  • HTML code - for example ("<div></div>")
  • New DOM element - for example (document.createElement("div"))
  • Existing elements - for example ($(".div1"))

Existing elements will not be moved, they will only be copied and wrapped around the selected elements.

More examples

Use the new element to wrap
Create a new DOM element to wrap each selected element.