/* add interval to a variable */ var flashing = setInterval(function(){ $('.flash').toggleClass('red'); },300); /* add a timerout function to clear the intervalfunction */ setTimeout(function(){ clearInterval(flashing); },1500);