如何解决jQuery-排除单击元素的父元素
| 我必须在jQuery元素集(\'。fav \')中排除单击元素的父级。 有人对我有什么建议吗?$(\'.fav .favFrame\').click(function(){
$(\'.fav\').fadeOut(400); //exclude the .fav that child .favFrame was clicked here
});
谢谢
解决方法
使用
.not()
:
$(\'.fav .favFrame\').click(function(){
$(\'.fav\').not($(this).parent()).fadeOut(400); //exclude the .fav that child .favFrame was clicked here
});
,尝试这个:
$(\'.fav .favFrame\').click(function(){
var notThis = $(\'.fav\').not($(this).parent());
notThis.fadeOut(400); //fade all except this parent
});
小提琴:http://jsfiddle.net/maniator/djx2M/
,试试这个(即使.fav不是favFrame的直接父代,也可以这样做):
$(\'.fav .favFrame\').click(function(){
$(\'.fav\').not($(this).closest(\".fav\")).fadeOut(400);
});
,$(\'.fav .favFrame\').click(function() {
var myParent = $(this).closest(\'.fav\');
$(\'.fav\').not(myParent).fadeOut(400);
});
这样,您不想淡出的元素完全不会受到影响。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。