我想在 JavaScript 中删除 <strong>
带有功能的标签:myfunc(this)
<strong><a href="#" onclick="myfunc(this)">mylink</a></strong>
我确实想清理代码,所以只有<strong>
需要删除标签
最佳答案
这应该完全做到这一点:
function myfunc(node)
{
node.parentNode.parentNode.replaceChild(node, node.parentNode);
}
问题是它只能运行一次,因此您需要进行额外的检查:
function myfunc(node)
{
var parent = node.parentNode;
if (parent.nodeName === 'STRONG') {
parent.parentNode.replaceChild(node, parent);
}
}
关于javascript - 从子标签 <a> 中删除父标签 <strong>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16444454/