您的位置:首页 > Web前端 > JQuery

jquery .remove用法与实例

2013-09-05 20:23 459 查看
类似。remove()时,。remove()方法需要指出的DOM元素。我们使用。删除()当我们要删除该元素本身,以及它里面的一切。除了元素本身,所有绑定的事件和相关的元素jQuery的数据都被删除。 selectora选择过滤表达式匹配的元素的集合被删除。
类似。remove()时,。remove()方法需要指出的dom元素。我们使用。删除()当我们要删除该元素本身,以及它里面的一切。除了元素本身,所有绑定的事件和相关的元素jquery的数据都被删除。
考虑下面的html:
<div class="container">
<div class="hello">hello</div>
<div class="goodbye">goodbye</div>
</div>we can target any element for removal:
$('.hello').remove();this will result in a dom structure with the <div> element deleted:
<div class="container">
<div class="goodbye">goodbye</div>
</div>
如果我们有任何内部<div class="hello">嵌套元素的数量,他们将被删除,太。其他jquery的构造,以及被删除,如数据或事件处理程序。
我们还可以包括一个可选的参数选择。例如,我们可以重写前面的dom的去除代码如下:
$('div').remove('.hello');this would result in the same dom structure:
<div class="container">
<div class="goodbye">goodbye</div>
</div>
看个实例
<!doctype html>
<html>
<head>
<style>p { background:yellow; margin:6px 0; }</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<p>hello</p>
how are
<p>you?</p>
<button>call remove() on paragraphs</button>
<script>
$("button").click(function () {
$("p").remove();
});
</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: