展开所选元素Javascript或Jquery [英] Unwrap selected element Javascript or Jquery
本文介绍了展开所选元素Javascript或Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的HTML。
<span id="current" class="green unselctable" data-original-title="" title="">
Lorem Ipsum is simply dummy
</span>
我选择 $(#current)
但如果我使用jQuery unwrap函数,那么父标记就会被删除。
I'm selecting with with $("#current")
but if I use the jQuery unwrap function the parent tag gets removed.
有没有办法在不解析字符串的情况下删除JavaScript或jQuery中的span并将其附加到dom?
Is there any way to remove the span in JavaScript or jQuery without parsing the string and appending it to the dom?
编辑
我想保留div的内容。我只想删除标签。
Edit I wanna keep the content of the div. I just want the tag removed.
推荐答案
$("#current").contents().unwrap();
contents()
将返回所有孩子 #current
,包括文本节点, unwrap()
可以应用于文本节点。
contents()
will return all the children of #current
, including text nodes, and unwrap()
can be applied to text nodes.
这篇关于展开所选元素Javascript或Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文