removechild 从父节点上删除某个子节点

  1. <div id="app">
  2. <p>one</p>
  3. <p id="two">two</p>
  4. <button id="btn">点击消失</button>
  5. </div>
  6. <!-- removeChild 从父节点上删除某个子节点
  7. parentElment.removeChlid(childElement)
  8. remove();
  9. -->
  10. <script>
  11. var app=document.getElementById("app");
  12. var two=document.getElementById("two");
  13. var btn=document.getElementById("btn");
  14. btn.onclick=function(){
  15. app.removeChild(two);
  16. }

remove() 方法

  1. <div id="app">
  2. <p>one</p>
  3. <p id="two">two</p>
  4. <button id="btn">点击消失</button>
  5. </div>
  6. <script>
  7. var app=document.getElementById("app");
  8. var two=document.getElementById("two");
  9. var btn=document.getElementById("btn");
  10. btn.onclick=function(){
  11. two.remove();
  12. }