jQuery unwrap()

The jQuery unwrap() method removes the parent element of the selected elements.

Syntax:

$(selector).unwrap()

Example1:

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

Example2:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("p").wrapAll("<div></div>");
});
$("#btn2").click(function(){
$("p").unwrap();
});
});
</script>
<style>
div{background-color: turquoise;
}
</style>
</head>
<body>
<p>Hello</p>
<p>Guys!</p>
<button id="btn1">Wrap All</button>
<button id="btn2">Unwrap</button>
</body>
</html>

Example3:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("p").wrapAll("<div></div>");
});
$("#btn2").click(function(){
$("p").unwrap();
});
});
</script>
<style>
div{background-color: turquoise;width: 120px;
height: 200px;
margin: 5px;padding:2px; border:2px solid red;
}
</style>
</head>
<body>
<p>Hello</p>
<p>Guys!</p>
<button id="btn1">Wrap All</button>
<button id="btn2">Unwrap</button>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com