- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- <title>
- </title>
- <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js">
- </script>
- <style>
- .test1 { background: #bbffaa; } .test2 { background: yellow; }
- </style>
- </head>
- <body>
- <h2>
- 通过jQuery remove方法移除元素
- </h2>
- <div class="test1">
- <p>
- p元素1
- </p>
- <p>
- p元素2
- </p>
- </div>
- <div class="test2">
- <p>
- p元素3
- </p>
- <p>
- p元素4
- </p>
- </div>
- <button>
- 通过点击jQuery的empty移除元素
- </button>
- <button>
- 通过点击jQuery的empty移除指定元素
- </button>
- <script type="text/javascript">
- $("button:first").on('click',
- function() {
- //删除整个 class=test1的div节点
- $(".test1").remove()
- }) $("button:last").on('click',
- function() {
- //找到所有p元素中,包含了3的元素
- //这个也是一个过滤器的处理
- $("p").remove(":contains('3')")
- })
- </script>
- </body>
- </html>
来源: http://www.bubuko.com/infodetail-1959969.html