jQuery unwrap()
method is the used to remove the parent element of the selected elements.
Below the syntax of unwrap()
.
$(selector).wrap();
jQuery unwrap()
method is the used to remove the parent element of the selected elements.
Below the syntax of unwrap()
.
$(selector).wrap();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery unwrap()</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
div{font-size:16px;height:40px;line-height:30px;width:300px;background:#11a286;padding:5px;color:#FFF;margin:0 0 10px 0}
</style>
<script>
$(document).ready(function() {
$("#button").click(function() {
$("p").unwrap();
});
});
</script>
</head>
<body>
<div>
<p>This is a paragraph.</p>
</div>
<button style="margin:0 0 10px 0;background:#e8e8e8;" class="btn" id="button">Click here to remove the parent element of p element</button><br />
</body>
</html>