var div = document.getElementById('d'), cmd = +div.dataset.timer; div.innerHTML = cmd; var timerId = setInterval(function() { console.log(cmd) div.innerHTML = cmd; cmd-- if(cmd < 0){ window.clearInterval(timerId); } }, 1000);