[英]jquery - run function on each element except the one that was clicked
作为一些示例代码,我可能会有这样的事情:
$('a.parent').click(function(){
$('a.parent').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
$(this).animate({
width: '160px'
},200,function(){
});
});
问题是我不希望被点击的元素动画为140px宽度,然后再回到160px。
有没有办法只在一组中没有点击的元素上运行'each'? 或者,还有更好的方法?
你可以使用:not(this)so change:
$('a.parent').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
至 :
$('a.parent:not('+this+')').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
或者在$('a.parent')之后使用.not(this),所以:
$('a.parent').not(this).each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.