wrapInner() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:wrapInner

Description

The wrapInner() method wraps HTML element(s) around the innerHTML of each selected element.

Syntax

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
  • index - the index position of the element in the set

The following code shows how to Wrap a <b> element around the content of each <p> element:

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").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>

Related Tutorials