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.4.1/jquery.min.js"> </script>//from www .jav a 2s. c o m <script> $(document).ready(function(){ $("button").click(function(){ $("p").wrapInner("<b></b>"); }); }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>test</button> </body> </html>
The wrapInner()
method wraps HTML element(s) around the innerHTML of each selected element.
$(selector).wrapInner(wrapping_Element,function(index))
Parameter | Optional | Description |
---|---|---|
wrapping_Element | Required. | HTML element(s) to wrap around the content of each selected element Possible values: HTML elements jQuery objects DOM elements |
function(index) | Optional. | sets a function that returns the wrapping element index - the index position of the element in the set |