Try the following:
$(document).ready(function() { $('label').hover(function() { var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')'; $(this).stop().animate( { color: hue }, 500); },function() { $(this).stop().animate( { color: '#000' }, 500); }); });
Also see my jsfiddle .
=== UPDATE ===
function startAnimation(o) { var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')'; $(o.currentTarget).animate( { color: hue }, 500, function() { startAnimation(o); }); } $(document).ready(function() { $('label').hover( startAnimation, function() { $(this).stop().animate( { color: '#000' }, 500); } ); });
See my updated jsfiddle .
source share