The jQuery unwrap() method can be used to remove the parent of the selected element. If you unwrap the element for more than one time, it remove other parent elements too.
Syntax
The syntax of this method is given below:-
The method requires no parameter to pass and use the method.
Description of the Parameters
The description of these parameters is given below.
Parameter Name | Description |
---|---|
selector | Specify the element to select and remove the parent element to unwrap. You can use the element tag name, class name, or id to select. It is a required field. |
jQuery unwrap() Method to Remove Parent Element
If you want to remove the parent element of the selected element, you have to use the jQuery unwrap() method as given below. It unwrap the selected element when you click the button element.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script> $(document).ready(function(){ $('.mybtn').click(function(){ $("p").unwrap(); }); }); </script> <style> div{ background:yellow; color:#000; padding:10px; } </style> <div> <p>This is my paragraph. <b>Unwrap element using the unwrap() method</b></p> </div> <button type="button" class="mybtn">Click to Remove</button> |
The example contains the paragraph element inside the div element. The method removes the div element which is the parent of paragraph element.
You may also like to read
I hope you like this tutorial on jQuery unwrap() method. If you have any queries regarding the tutorial, please comment below.
References