How to remove div without internal elements

I would like to remove a single div element, but without its children. For example, let's say that I have one div with an id wrapper and inside it is 5 paragraphs.

I want to remove only the div shell, but leave the paragraphs alive. I tried remove () and detach (), but they both clear the internal elements.

Any tips?

+4
source share
4 answers

http://api.jquery.com/unwrap/ should do this:

The .unwrap() method removes the parent element. This is actually the opposite of the method . Wrap () . The relevant elements (and their siblings, if any) replace their parents in the DOM structure ...

+13
source

jsFiddle demo

 $('#element').contents().unwrap(); 
+6
source

Check out .replaceWith()

 $('#theDiv').replaceWith($('#theDiv').contents()); 
+4
source
 $('#yourdivIDtoremove').replaceWith($(this).text()); 

should do;)

0
source

All Articles