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);
});
这样,您不想淡出的元素完全不会受到影响。     

要回复问题请先登录注册