As some example code, I might have something like this:
$('a.parent').click(function(){
$('a.parent').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
$(this).animate({
width: '160px'
},200,function(){
});
});
The problem is that I don't want the element that was clicked to animate to 140px width and then back to 160px.
Is there a way to run 'each' on only the elements in a set who were not clicked? Or is there a better way?
you can use :not(this) so change :
$('a.parent').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
to :
$('a.parent:not('+this+')').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
or use .not(this) after $('a.parent') , so :
$('a.parent').not(this).each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With