Javascript 使用 jQuery 删除 <div>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7820162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove <div> using jQuery
提问by Dail
I have this HTML code:
我有这个 HTML 代码:
<div id="note_list">
<div class="note">
Text 1
<a href="">X</a>
</div>
<div class="note">
Text 2
<a href="">X</a>
</div>
<div class="note">
Text 3
<a href="">X</a>
</div>
<div class="note">
Text 4
<a href="">X</a>
</div>
<div class="note">
Text 5
<a href="">X</a>
</div>
</div>
Now I would like to use jQuery to deletea <div>
element AFTER the 'X' clicking, is it possible?
现在我想使用 jQuery在“X”点击后删除一个<div>
元素,这可能吗?
First X closes:
第一个 X 关闭:
<div class="note">
Text 1
<a href="">X</a>
</div>
etc etc.
Can I remove a divwithout using id=""
?
等等等等。我可以不使用div来删除divid=""
吗?
Thank you!
谢谢!
回答by Manuel van Rijn
$(".note a").click(function(e) {
e.preventDefault();
$(this).parent().remove();
});
or instead of remove()
you could use slideUp()
或者remove()
你可以使用slideUp()
回答by lonesomeday
回答by Sedat Ba?ar
$(".note a").click(function() {
$(this).parent().remove();
});
u can check here http://jsfiddle.net/3JCR7/1/
你可以在这里查看http://jsfiddle.net/3JCR7/1/