Javascript examples for jQuery Method and Property:wrapInner
The wrapInner() method wraps HTML element(s) around the innerHTML of each selected element.
Parameter | Require | Description |
---|---|---|
wrappingElement | Required. | HTML elements/jQuery objects/DOM elements to wrap around the content of each selected element |
function(index) | Optional. | a function that returns the wrapping element |
The following code shows how to Wrap a <b> element around the content of 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 w w .j av a2 s. com*/ }); </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>