jQuery - exclude the parent of the clicked element
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.
精彩评论