Megh Gandhi
Megh Gandhi

Reputation: 49

How to remove a div without removing its children?

For example http://jsfiddle.net/skpfknxo/

It removes the div #test along with its children #test2 and #test3. I want to remove #test without removing its children.

How could this be done?

Upvotes: 2

Views: 114

Answers (1)

guradio
guradio

Reputation: 15555

$( "button" ).click(function() {
  $( "#test2" ).unwrap();
});

demo

The .unwrap() method removes the element's parent. This is effectively the inverse of the .wrap() method. The matched elements (and their siblings, if any) replace their parents within the DOM structure.

Upvotes: 6

Related Questions