开发者

Jquery unwrap() method? [duplicate]

This question already has answers here: jQuery : remove element except inside element (4 answers) Closed 8 years ago.

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?


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


A quick Google search reveals that there is such functionality, in the form of a small 576 byte plugin called jqueryunwrap. I have not tried it personally, but it is worth a shot. ;)


$("p").unwrap() will unwrap the wrapping div....................I hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜