zoukankan      html  css  js  c++  java
  • 原生js怎么删除一个 div

    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    2. <html xmlns="http://www.w3.org/1999/xhtml">  
    3. <head>  
    4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
    5. <title>增加删除DIV的JS写法</title>  
    6. </head>  
    7.   
    8. <body>  
    9. <div id="main">  
    10.     <div id="box">111</div>  
    11.     <div class="box2">222</div>  
    12. </div>  
    13. <script type="text/javascript">  
    14. var box = document.getElementById("box");  
    15. var main = document.getElementById("main");  
    16. var newMask = document.createElement("div");  
    17. newMask.id ="newMask";  
    18. main.appendChild(newMask);   
    19. if(box){  
    20.     box.parentNode.removeChild(box);  
    21. }  
    22. else{  
    23.     alert("没有这个div");  
    24. }  
    25. </script>  
    26. </body>  
    27. </html>  
    [html] view plain copy
     
    1. <div id="main">  
    2.     <div id="box">111</div>  
    3.     <div class="box2">222</div>  
    4. </div>  
    5. <script type="text/javascript">  
    6. var box = document.getElementById("box");  
    7. box.parentNode.removeChild(box);  
    8. </script>  
  • 相关阅读:
    ceph部署与问题
    openstack常见问题汇总
    css
    html
    zookeeper
    ZAB协议
    快速排序
    Servlet梳理
    tomcat性能优化梳理
    tomcat梳理
  • 原文地址:https://www.cnblogs.com/kongxc/p/8028339.html
Copyright © 2011-2022 走看看