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>