Can someone tell me why return false is not working? I just want to check if current is yellow. If it is yellow class don’t do nothing (return false). The problem is when you click a button it runs its thing again but I want to avoid that.
Here’s the Fiddle of the problem.
/*INSIDE THIS CODE RETURN FALSE NOT WORKING!!*/
$('.yellowcontroll').click(function(){
if($yellow.after('.current').length){
$('.yellow').show();
$('.slideswrapper:not(:animated)').animate({'marginLeft':'-=100'},1000,function(){
$('.current').removeClass('current').hide();
$('.yellow').addClass('current');
$('.slideswrapper').css({'margin-left':'0px'});
if($('.current').is($('.slideswrapper div:last'))){
$('.blue,.green,.red').clone().insertAfter('.slideswrapper div:last');
}
if($('.current').is($('.red'))){
$('.red').prevAll().remove(':not(.yellow)');
$('.yellow').insertAfter($('.slideswrapper div:last'));
}
/*THIS IS NOT WORKING AS EXPECTED!!*/
if($('.current').is($('.yellow'))){
return false;
}
});
}
});
The problem is that you are returning false from the callback to your animation, not the event callback.
If what you are looking for is for nothing to happen when you click the second time then you could move the condition and return false to the front of the click callback: