Jquery unwrap () method?

There wrap()

is a nifty method in jquery named that will wrap the selected element inside a new element, e.g .:

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 I need something that unfolds so that the above process will be canceled. It looks like the problem is that when you select a bad item (say, an unnecessary table), it always grabs what's inside it, so if I want to delete all <td>

s, I left nothing, because that was deleted td

and that- then inside.

Is there a standard reliable way to remove items, but only keep children / ancestors?

+2


source to share


3 answers


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



+8


source


A quick Google search reveals that such functionality exists in the form of a small 576 byte plugin called jqueryunwrap . I haven't tried it personally, but it's worth it.;)



+1


source


$("p").unwrap()

expands the wrapper div. I hope this helps

0


source







All Articles