suludi suludi - 1 year ago 94
jQuery Question

How to remove div without inner elements

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

I want to remove only the wrapper div, but to leave paragraphs alive. I have tried both remove() and detach(), but they both clean out the inner elements.

Any advice?

Answer Source should do it:

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...