【发布时间】:2021-03-09 06:56:35
【问题描述】:
我正在尝试将 div “向上”移动一个级别并摆脱块引用。正如您在this fiddle 中看到的,当您单击“更改”时,不会保留粗体字体。我也尝试过使用 innerHTML 和 innerText 而不是 textContent 但都没有奏效。这是 HTML:
<html>
<div id="outerdiv">
<blockquote><div id="innerdiv"><b>Hello </b>Text 1</div></blockquote>
</div>
<span onclick="removeblockquotes(this)">Change</span>
</html>
还有 JS:
function removeblockquotes(e)
{for (const b of document.querySelectorAll('blockquote')) {
if (!b.closest('div')?.parentElement.closest('div')) {
b.replaceWith(b.textContent);
}
}
}
【问题讨论】:
标签: javascript html dom innerhtml replacewith