Jquery:$().remove()
jQuery remove() 方法删除被选元素及其子元素, 即删除元素自身。
<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>删除 div 元素button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").remove();
});
});
script>
body>
jQuery empty() 方法删除被选元素的所有子元素。
<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>清空 div 元素button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").empty();
});
});
script>
body>
JS
三种情况:
xxx.remove()
xxx.parentNode.removeChild(xxx)
父.removeChild(子)
xxx.parentNode.parentNode.removeChild(xxx的父元素);
jQuery 删除元素 (w3school.com.cn)
js实现删除页面元素_兰兰的小窝的博客-CSDN博客_js删除元素