Javascript examples for jQuery Method and Property:wrapAll
The wrapAll() method wraps specified HTML element(s) around all selected elements.
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:
<!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>