var secs = 599; function decrementTimer() { var currentMinutes = "0" + Math.floor(secs / 60); var currentSeconds = Math.floor((secs % 60)); if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds; var timeLeft = currentMinutes + ":" + currentSeconds; $("#whiteTimeLeft").text(timeLeft); secs-- } var clearDecrementTimer; $("#start").click(function(){ clearDecrementTimer = setInterval(function(){ decrementTimer() }, 1000); }); $("#stop").click(function(){ clearInterval(clearDecrementTimer); }); ===============================================================================================================

var decrementTimer = function(secs) { var currentMinutes = "0" + Math.floor(secs / 6000); var currentSeconds = Math.floor((secs%60)); if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds; var timeLeft = currentMinutes + ":" + currentSeconds; console.log(timeLeft); $("#whiteTimeLeft").text(timeLeft); if(secs > 0) setTimeout(function(){decrementTimer(secs-1)},1000); }; decrementTimer(59999); ===============================================================================================================

var element = document.getElementById("whiteTimeLeft"); var time = new Date(); time.setMinutes(10); time.setSeconds(0); function decrementTimer() { element.innerHTML = time.getMinutes() + ":" + time.getSeconds(); // todo: pad zeroes time.setSeconds(time.getSeconds() - 1); setTimeout(decrementTimer, 1000); } decrementTimer();