[英]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'). 我必须在jQuery元素集('.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 谢谢
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/ 小提琴: http : //jsfiddle.net/maniator/djx2M/
Try this(this works even if .fav is not the direct parent of favFrame): 试试这个(即使.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);
});
This way, the element you don't want to fade out doesn't get affected at all. 这样,您不想淡出的元素完全不会受到影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.