JavaScript setInterval & clearInterval example:
JSFiddle example link
var i = 3; var interval = setInterval(function() { if (i > 0) { $("div").html("Running " + i--); } else { clearInterval(interval); $("div").html("Stopped"); } }, 2000);
JSFiddle example link