原生js怎么删除一个 div
2024-08-26 01:06:32
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>增加删除DIV的JS写法</title>
- </head>
- <body>
- <div id="main">
- <div id="box">111</div>
- <div class="box2">222</div>
- </div>
- <script type="text/javascript">
- var box = document.getElementById("box");
- var main = document.getElementById("main");
- var newMask = document.createElement("div");
- newMask.id ="newMask";
- main.appendChild(newMask);
- if(box){
- box.parentNode.removeChild(box);
- }
- else{
- alert("没有这个div");
- }
- </script>
- </body>
- </html>
- <div id="main">
- <div id="box">111</div>
- <div class="box2">222</div>
- </div>
- <script type="text/javascript">
- var box = document.getElementById("box");
- box.parentNode.removeChild(box);
- </script>
最新文章
- How to configure security of ActiveMQ ?
- 关于eclipse保存代码很慢,提示the user operation is waiting的问题
- Android 学习笔记 Service
- 关押罪犯(codevs 1069)
- 第一个简单的android项目
- 我学C的那些年[ch01]:浅淡C语言的编译过程
- SANSA 上上洛可可 贾伟作品 高山流水 香炉 香插香台香具 高端商务礼品 黑色【正品 价格 图片 折扣 评论】_尚品网ShangPin.com
- POJ1008 1013 1207 2105 2499(全部水题)
- Android Application Fundamentals——Android应用程序基础知识
- 【leetcode82】Linked List Cycle
- Java 程序员必须了解的 7 个性能指标
- 『TensorFlow』命令行参数解析
- 老菜鸟学习:Javascript 将html转成pdf
- Dreamweaver 2
- 【bzoj5118】Fib数列2 费马小定理+矩阵乘法
- c# XML读取
- iOS中的多线程 NSOperation
- perl学习(二)正则表达式
- mysql 触发器 trigger用法 three (稍微复杂的)
- curl基于URL的文件传输工具
热门文章
- C#基础视频教程2 常见数据类型和属性方法
- Jquery重新学习之二[属性attr(),removeAttr(),prop(),removeProp()]
- vim 查找和替换命令 替换/n和\n
- Creating a Fragment: constructor vs newInstance()
- jquery remove()不兼容问题解决方案
- Centos 开启telnet-service服务
- Linux命令-权限管理命令:chmod
- idea 更换编辑器背景图片
- Windows7清除图标缓存
- express 设置header解决跨域问题