开发者

jQuery - exclude the parent of the clicked element

开发者 https://www.devze.com 2023-02-24 21:46 出处:网络
i have to ecxlude the parent of a clicked element in a jQuery set of element (\'.fav开发者_开发百科\').

i have to ecxlude the parent of a clicked element in a jQuery set of element ('.fav开发者_开发百科'). Does anybody have any advice for me how to do that?

$('.fav .favFrame').click(function(){
    $('.fav').fadeOut(400);          //exclude the .fav that child .favFrame was clicked here
});

Thx


Use .not():

$('.fav .favFrame').click(function(){
    $('.fav').not($(this).parent()).fadeOut(400); //exclude the .fav that child .favFrame was clicked here
});


try this:

$('.fav .favFrame').click(function(){
    var notThis = $('.fav').not($(this).parent());
    notThis.fadeOut(400); //fade all except this parent
});

fiddle: http://jsfiddle.net/maniator/djx2M/


Try this(this works even if .fav is not the direct parent of 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);
});

This way, the element you don't want to fade out doesn't get affected at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消