views:

247

answers:

2

I have some JQuery code in the click event handler for a checkbox that updates the value of a span control on the page, then animates the background color of the span tag to yellow and then fade back to white in about a second to draw attention to the user that the value of the span has changed. The problem is that if a user clicks repeatedly on the checkbox, then the animation occurs over and over for how ever many times the user clicked. Any one know how to prevent the JQuery animation from occuring if an animation is already in progress.

+1  A: 

Check this

sshow
Awesome, that works perfectly! Thanks!
Russ Clark
+2  A: 

Simply call stop() on the object before animating it:

 $('#button').click( function() {
  $('#animatedSpan').stop().animate( { } );
 });
Pim Jager