Home >>jQuery Tutorial >jQuery unwrap() Method

jQuery unwrap() Method

jQuery unwrap() Method

jQuery unwrap() method in jQuery is used to removes the parent element of the selected elements.

Syntax:
$(selector).unwrap()
Here is an Example of jQuery unwrap() 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").unwrap();
});
});
</script>
<style>
.UnWrap{background-color: dodgerblue;}
.UnWrap1{background-color: orange;}
</style>
</head>
<body>
<div class="UnWrap">
<p class="txt1">This is a paragraph inside a div element.</p>
</div>
<article class="UnWrap1">
<p class="txt1">This is a paragraph inside an article element.</p>
</article>
<button class="btn1">Click me to Remove</button>
</body>
</html>

Output:

This is a paragraph inside a div element.

This is a paragraph inside an article element.


No Sidebar ads