How to Remove Parent Element of any Selected Child Element


You want to remove parent element of any selected element. You can use JQuery unwrap method as shown below.

Let's say you have a div element and a nested span element in your HTML source.

<div id="parent" style="background-color:yellow; padding:5px;"> 

   <span id="child" style="background-color:green;">I am alone, because my parent DIV has been removed!</span> 

</div>

You can remove the parent div element of child span as follows:

$("#child").unwrap();

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments