jQuery wrapAll() Method

jQuery wrapAll() method wraps an HTML structure (element's) around all selected elements.

Syntax

Here is a wrapAll() method syntax

$(selector).wrapAll( wrappingElement );
Parameter Type Description
wrappingElement Selector
htmlString
Element
jQuery
Required. Specifies the HTML structure to wrap around all matched elements.

Example

Here, in this example all selected element wraps into <div> element.

<!DOCTYPE html>
<html>
<head>
  <title>jQuery wrap() method</title>
  <script src="jquery-latest.min.js"></script>
  <script>
    $(document).ready(function(){
      $("button").click(function(){
        $("p").wrap("<div></div>");
      });
    });
  </script>
  <style type="text/css">
    div{
      background-color: pink;
      border:1px dashed black;
      text-align: center;
    }
  </style>
</head>
<body>
  <p class="param first">First paragraph text</p>
  <br />
  <button>Click here to call wrap() method</button>
</body> 
</html>

Run it...   »