javascript jquery 获取最近的父级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8168202/
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
jquery get nearest parent
提问by mononym
Possible Duplicate:
nearest ancestor node in jQuery
可能的重复:
jQuery 中最近的祖先节点
html:
html:
<div class="post">
<h2><a href="#" title="">Pellentesque</a></h2>
<p><a href="#" title="" class="more">More</a></p>
</div>
jQuery
jQuery
$('.more').bind("hover", function(){
$(this).parent('.post').hide() ;
});
on hover (.more) i want to hide the post, but it does nothing if i use parents() instead it deletes ALL the .posts on the page
在悬停 (.more) 时,我想隐藏帖子,但如果我使用 parents() 则它什么也不做,它会删除页面上的所有 .posts
any help appreciated
任何帮助表示赞赏
回答by Exception
回答by Francis
Use jQuery.closest : http://api.jquery.com/closest/
使用 jQuery.closest :http: //api.jquery.com/closest/