删除节点
步骤:``
先获取父节点,再通过父节点删除节点(不能自己删除自己)
案例一
<div id = "father">
<h1>标题一</h1>
<p id = "p1">p1</p>
<p class = "p2">p2</p>
</div>
<script>
let self = document.getElementById('p1');
let father = document.getElementById('father');
let childrens = father.children; //获取父节点所有的子节点
</script>
案例二:
<div id = "father">
<h1>标题一</h1>
<p id = "p1">p1</p>
<p class = "p2">p2</p>
</div>
<script>
let self = document.getElementById('p1');
let father = self.parentElement;
let childrens = father.children; //获取父节点所有的子节点
</script>
删除是一个动态的过程,删除多个节点的时候,children是在时刻变化的,删除节点的时候一定要注意