wrapAll() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:wrapAll

Description

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

Syntax

Parameter Require Description
wrappingElement Required. HTML elements/jQuery objects/DOM elements to wrap around the selected elements

The following code shows how to Wrap a <div> element around all <p> elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").wrapAll("<div></div>");
    });//w  w w. java 2s .  c  om
});
</script>
<style>
div{background-color: yellow;}
</style>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<button>Wrap a div element around all p elements</button>

</body>
</html>

Related Tutorials