代码示例:(标识:js_dom_elementremove)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript HTML DOM</h1>

<p>删除 HTML 元素:</p>

<div>
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>

<button onclick="myFunction()">删除元素</button>

<script>
function myFunction() {
document.getElementById("p1").remove();
}
</script>

</body>
</html>
运行结果: