删除< span>标记,而内容保持完整,仅使用javascript [英] Removing <span> tag while leaving content intact, with just javascript
本文介绍了删除< span>标记,而内容保持完整,仅使用javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在突出显示页面,发现使用文本选择并添加跨度时最受欢迎的示例是切换到designMode并运行execCommand
I'm doing some in page highlighting, and found the most popular example when using text selection and adding spans is by switching to designMode and running execCommand
How can I highlight the text of the DOM Range object?
尽管创建后如何删除span标签,但没有后续措施. 我看到了一些使用jquery和replaceWith的示例,但没有使用纯JavaScript的示例.
There's no follow up though on how to remove the span tags once created. I saw some examples using jquery and the replaceWith, but none with straight javascript.
推荐答案
您应该可以执行以下操作:
You should be able to do something like:
// Where span is a reference to the span to be replaced
var text = span.textContent || span.innerText;
var node = document.createTextNode(text);
span.parentNode.replaceChild(node, span);
这篇关于删除< span>标记,而内容保持完整,仅使用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文