[url]http://www.w3school.com.cn/jquery/jquery_ref_manipulation.asp[/url]
1.empty()删除匹配的元素集合中所有的[color=red]子节点[/color]。
2.detach() 从 DOM 中移除匹配元素集合。
移除被选元素,包括所有文本和子节点。
保留 jQuery 对象,保留所有绑定的事件、附加的数据。
3.remove() 方法移除[color=red]被选元素[/color],包括[color=red]所有文本和子节点[/color]。
保留 jQuery 对象可以在将来再使用这些匹配的元素,
与 detach() 不同:不保留元素的 jQuery 数据(绑定的事件、附加的数据等都会被移除)。
1.empty()删除匹配的元素集合中所有的[color=red]子节点[/color]。
2.detach() 从 DOM 中移除匹配元素集合。
移除被选元素,包括所有文本和子节点。
保留 jQuery 对象,保留所有绑定的事件、附加的数据。
3.remove() 方法移除[color=red]被选元素[/color],包括[color=red]所有文本和子节点[/color]。
保留 jQuery 对象可以在将来再使用这些匹配的元素,
与 detach() 不同:不保留元素的 jQuery 数据(绑定的事件、附加的数据等都会被移除)。
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
<!--//保留p对象的内容,仍旧可以将原有jquery对象的内容追加-->
$("body").append($("p").detach());
<!--移除h2,可见h2对象的内容一同被移除-->
$("body").append($("h2").remove());
<!--清空body对象的子节点-->
$("body").empty();
});
});
</script>
<body>
<p>This is a para.</p>
<h1>hi,wjy</h1>
<h2>hello world!</h2>
<button>移除元素</button>
</body>