我正在尝试做与此问题类似/相同的事情: 如何在 JavaScript 中仅删除父元素而不是其子元素?
<div>
This is some text here
<h2>This is more text</h2>
</div>
我想要的只是删除 H2 标签。结果应该是:
<div>
This is some text here
This is more text
</div>
假设我已经有了 H2 元素:
if (parentElement.nodeName.toLowerCase() == "h2") {
//now what? I basically want to this: $.replaceWith(parentElement.innerText)
//just without jQuery
}