Jquery unwrap() method?

dom, javascript, jquery

Solution

In JQuery 1.4 unwrap() was added: http://api.jquery.com/unwrap/

Problem

There is a great method in jquery called `wrap()` that will wrap a selected element inside a new element, like so: Start with: ``` <p>I wish I was wrapped!</p> ``` Add code: ``` $("p").wrap("<div></div>"); ``` End with: ``` <div><p>I wish I was wrapped!</p></div> ``` But what I need is something that will unwrap, so that the above process is reversed. It seems that the issue is that when you select a bad item (let's say an unnecessary table) that it always grabs what is inside it as well, so if I want to remove all `<td>`s, I am left with nothing, since that removed the `td` and anything inside. Is there a standard reliable way of removing elements but leaving any children/ancestors alone?

Original source

Related problems