Javascript examples for jQuery Method and Property:wrap
The wrap() method wraps specified HTML element(s) around each selected element.
Parameter | Require | Description |
---|---|---|
wrappingElement | Required. | HTML elements/jQuery objects/DOM elements to wrap around each selected element |
function(index) | Optional. | a function that returns the wrapping element |
The following code shows how to Wrap a <div> element around each <p> element:
<!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").wrapInner("<b></b>"); });// w ww .jav a2 s. c o m }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Wrap a b element around the content of each p element</button> </body> </html>