Home >>jQuery Tutorial >jQuery wrapAll() Method

jQuery wrapAll() Method

jQuery wrapAll() Method

jQuery wrapAll() method in jQuery is used to wraps specified HTML elements around all selected elements.

Syntax:
$(selector).wrapAll(wrappingElement)

Parameter Values

Parameter Description
wrappingElement It is a required parameter and is used to specifies what HTML element to wrap

Possible values:

  • jQuery objects
  • HTML elements
  • DOM elements
Here is an Example of jQuery wrapAll() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".txt1").wrapAll("<div></div>");
});
});
</script>
<style>
div{background-color: orange;}
</style>
</head>
<body>
<p class="txt1">This is a paragraph.</p>
<p class="txt1">This is another paragraph.</p>
<button class="btn1">Click me to Wrap a div element</button>
</body>
</html>