jQuery > Manipulations methods

.unwrap() - Unwrap parent element in jQuery

How to unwrap the parent element from the specific element in jQuery?


To unwrap (remove) the parent element from the specific element, unwrap() method can be used.

 <script>
        $("#divP").unwrap(););
  </script>

Above code snippet will remove the parent element of the element whose id is “divP”. Let's assume that "divP" element is kept inside another div whose id is "divScroll" like below.

<div id="divScroll" style="height:100px;width:300px;overflow:scroll;">
 <p id="divP" style="height:300px;width:500px;background:#efefef;">
     This is looking nice.
 </p>
</div>

After unwrapping, above code snippet will become

<p id="divP" style="height:300px;width:500px;background:#efefef;">
    This is looking nice.
</p>

Notice that the starting div tag and ending div tag of the parent of "divP" div has been removed.

 Views: 6985 | Post Order: 58



Write for us






Hosting Recommendations