删除父级但使用jQuery保留子级 [英] Remove parent but keep children using jQuery
本文介绍了删除父级但使用jQuery保留子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除父级并使用jQuery将子级保留在HTML中。这有效:
I would like to remove the parent and keep the children in my HTML using jQuery. This works:
$('#my_span').children().insertBefore('#my_span').end().end().remove();
然而,它删除了文本和注释节点类型 - 我如何修改它以便保持文本?
However, it removes the text and comment node types - how can I amend this so that I keep the text?
很高兴用纯Javascript做到这一点。
Happy to do this with pure Javascript too.
推荐答案
正如@Cᴏʀʏ所说, unwrap()
应该可以帮助你实现这一点。
As @Cᴏʀʏ says, unwrap()
should help you acheive this.
或者,你可以做类似的事情这个:
Alternatively, you could do something like this:
$('#my_span').parent().html($('#my_span').html());
这篇关于删除父级但使用jQuery保留子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文