You can use setInterval() for this.
Note that make sure that countdownElement has an existing text node, which can be any space. If you cannot guarantee this, simply use innerHTML or innerText/textContent .
window.onload = function() { var countdownElement = document.getElementById('countdown'), downloadButton = document.getElementById('download'), seconds = 10, second = 0, interval; downloadButton.style.display = 'none'; interval = setInterval(function() { countdownElement.firstChild.data = 'You can start your download in ' + (seconds - second) + ' seconds'; if (second >= seconds) { downloadButton.style.display = 'block'; clearInterval(interval); } second++; }, 1000); }
jsFiddle .
source share