Skip to content

Instantly share code, notes, and snippets.

@Beneboe
Created January 29, 2013 20:00
Show Gist options
  • Save Beneboe/4667222 to your computer and use it in GitHub Desktop.
Save Beneboe/4667222 to your computer and use it in GitHub Desktop.
Flexible countdown that can find out the countdown time automatically
function countdowntimer(element, secs) {
var i = (secs) ? secs : element.innerHTML;
var t1 = setInterval(function() {
if(i != 0){
i--;
}
else{
clearInterval(t1);
//timer ends here
}
element.innerHTML = i;
}, 1000);
}
countdowntimer(document.querySelector("span"));
<span>span</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment