私はこの質問と同様/同じことをしようとしています: 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
}