Parameter | Description |
---|---|
WrappingElement | It is a mandatory parameter. It specifies what HTML elements to wrap around each selected element. Its possible values are:
|
Function(index) | It is an optional parameter. It specifies a function that returns the wrapping element.
|
<!DOCTYPE html>
<html>
<head>
<title>jQuery wrap() Method</title>
<script src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").wrap("<div></div>");
});
});
</script>
<style>
div{background-color:#FF0;}
.btn{ padding:6px 15px;}
</style>
</head>
<body>
<p>www.freetimelearn.com</p>
<p>www.freetimelearning.com</p>
<button type="button" class="btn">Click Here! (wrap())</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>jQuery unwrap() Method</title>
<script src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").unwrap();
});
});
</script>
<style>
div{background-color:#F90; color:#FFF;}
article{background-color:#0099da; color:#fff;}
.btn{ padding:6px 15px;}
</style>
</head>
<body>
<div>
<p>www.freetimelearn.com</p>
</div>
<article>
<p>www.freetimelearning.com</p>
</article>
<button type="button" class="btn">Click Here! (unwrap())</button>
</body>
</html>
Parameter | Description |
---|---|
wrappingElement | It is a mandatory parameter. It Specifies what HTML element(s) to wrap around the selected elements Possible values:
|
<!DOCTYPE html>
<html>
<head>
<title>jQuery wrapAll() Method</title>
<script src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").wrapAll("<div></div>");
});
});
</script>
<style>
div{background-color:#F90;}
.btn{ padding:6px 15px;}
</style>
</head>
<body>
<p>www.freetimelearn.com</p>
<p>www.freetimelearning.com</p>
<button type="button" class="btn">Click Here! (wrapAll())</button>
</body>
</html>
wrapInner()
method is used to wrap an HTML structure around the content of each element in the set of matched element. This method can accept any string or object that could be passed to the $() factory function.Parameter | Description |
---|---|
wrappingElement | It is a mandatory parameter. It Specifies what HTML element(s) to wrap around the content of each selected element Possible values:
|
function(index) | It Specifies a function that returns the wrapping element
|
<!DOCTYPE html>
<html>
<head>
<title>jQuery wrapInner() Method</title>
<script src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").wrapInner("<b></b>");
});
});
</script>
<style>
div{background-color:#F90;}
.btn{ padding:6px 15px;}
</style>
</head>
<body>
<p>www.freetimelearn.com</p>
<p>www.freetimelearning.com</p>
<button type="button" class="btn">Click Here! (wrapInnerl())</button>
</body>
</html>