jQuery 删除或是清空某个HTML元素示例
2016-05-10 15:36
513 查看
jQuery使用下面两个方法来删除或是清空某个HTML元素。
remove() – 删除指定的元素(包括其子元素)
empty() – 清空指定元素的子元素
1.remove()
2.empty
转:http://www.jb51.net/article/53199.htm
remove() – 删除指定的元素(包括其子元素)
empty() – 清空指定元素的子元素
1.remove()
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JQuery Demo</title> <script src="scripts/jquery-1.9.1.js"></script> <script> $(document).ready(function () { $("button").click(function () { $("#div1").remove(); }); }); </script> </head> <body> <div id="div1" style="height: 100px; width: 300px; border: 1px solid black; background-color: yellow;"> This is some text in the div. <p>This is a paragraph in the div.</p> <p>This is another paragraph in the div.</p> </div> <br> <button>Remove div element</button> </body> </html>
2.empty
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JQuery Demo</title> <script src="scripts/jquery-1.9.1.js"></script> <script> $(document).ready(function () { $("button").click(function () { $("#div1").empty(); }); }); </script> </head> <body> <div id="div1" style="height: 100px; width: 300px; border: 1px solid black; background-color: yellow;"> This is some text in the div. <p>This is a paragraph in the div.</p> <p>This is another paragraph in the div.</p> </div> <br> <button>Empty the div element</button> </body> </html>
转:http://www.jb51.net/article/53199.htm
相关文章推荐
- jQuery事件绑定和委托实例
- jQuery事件的绑定、触发、及监听方法简单说明
- jQuery知识点:attr与prop的区别
- jquery中如何使用event.target
- jquery事件冒泡
- jquery设置cors跨域
- Jquery处理url.query
- 解决jquery无法找到其他父级子集问题的方法
- jquery eval解析JSON中的注意点介绍
- Jquery对象转js对象
- jQuery.grep
- JQuery入门(1) - 选择器
- jquery mobile 输入框无边框
- jquery获取input单选按钮点击事件及单选按钮值的方法
- 无刷新分页 jquery.pagination.js
- 页面引入jQuery mobile 底部出现loading字样
- jquery实现点击弹出可放大居中及关闭的对话框(附demo源码下载)
- jquery 加载等待效果
- jQuery选择器基础入门教程
- jquery实现图片上传前本地预览功能