Home >>jQuery Tutorial >jQuery wrapInner() Method

jQuery wrapInner() Method

jQuery wrapInner() Method

jQuery wrapInner() method in jQuery is used to wraps specified HTML element around the content of each selected element.

Syntax:
$(selector).wrapInner(wrappingElement,function(index))

Parameter Values

Parameter Description
wrappingElement It is a required parameter and is used to Specifies what HTML element to wrap around the content

Possible values:

  • jQuery objects
  • HTML elements
  • DOM elements
function(index) It is optional and is used to returns the wrapping element of a function
  • index – It is used to returns the index position of the element
Here is an Example of jQuery wrapInner() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".txt1").wrapInner("<b></b>");
});
});
</script>
</head>
<body>
<p class="txt1">This is First paragraph.</p>
<p class="txt1">This is Second paragraph.</p>
<button class="btn1">Click me to Wrap a content</button>
</body>
</html>

Output:

This is First paragraph.

This is Second paragraph.


No Sidebar ads