removeChild()

从DOM树上移除一个元素

  1. removeChild
  2. <div id="parent">
  3. <!-- <p>hello world</p> -->
  4. <div id="good">good</div>
  5. </div>
  6. <script>
  7. var parent = document.getElementById("parent")
  8. var good = document.getElementById("good");
  9. var p =document.createElement("p");
  10. p.innerHTML = "hello world"
  11. /*
  12. appendChild()
  13. 给元素增加节点
  14. */
  15. parent.appendChild(p);
  16. parent.removeChild(good);
  17. </script>
  1. ![image.png](https://cdn.nlark.com/yuque/0/2019/png/446381/1568119331646-d283a74a-ba7e-4912-b145-42e340bf26bb.png#align=left&display=inline&height=365&name=image.png&originHeight=365&originWidth=242&size=15325&status=done&width=242)