CodesJava

Easy learning with example program codes

jQuery wrapInner()

jQuery wrapInner() method wraps all the HTML structure around the content of each element of the selected element.

Syntax:

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

WrappingElement:

  • It is a compulsory parameter.
  • It is used to specify the HTML elements to be wrapped around the content of each selected element.
  • Its can accept HTML elements, jQuery objects and DOM elements as a value.

Function: It is an optional function to return the wrapping element.

Index: Index is passed as an argument of the function to specify the index position of the element in the set.

Example 1

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
$("button").click(function(){  
$("p").wrapInner("<em></em>");  
});  
});  
</script>  
</head>  
<body>  
<p>Hello!</p>  
<p>Nice to see you.</p>  
<button>Wrap Inner</button>  
</body>  
</html>

Try it

JS Bin on jsbin.com

Example 2

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
	$("button").click(function(){  
    	$("p").wrapInner("<div></div>");  
	});  
});  
</script>  
<style>  
div{background-color: turquoise;width: 120px;  
	height: 20px;    
	margin: 5px;padding:2px; border:2px solid red;
}  
</style>  
</head>  
<body>  
<p>Hello</p>  
<p>Guys!</p>  
<button>Wrap Inner</button>  
</body>  
</html>

Try it

JS Bin on jsbin.com

Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status