I have multiple html elements with the class "countdown":
<span data-seconds="95" class="countdown">00:01:35</span>
<span data-seconds="30" class="countdown">00:00:30</span>
and so on.. Now I want make a timer that countdown the value to 00:00:00, and then the page should be reload. This I have in my script:
// Countdown
setInterval(function(){
$(".countdown").each(function(){
var seconds = $(this).data('seconds');
if(seconds > 0) {
second = seconds - 1;
$(this).data('seconds', second)
$(this).html(second )
}
});
}, 1000);
This works perfectly for seconds ... but can somebody help me to convert this into the hh:mm:ss format? in php there is the awesome function gmdate("H:i:s", $seconds) function.. I wonder there is some similar in JS?
And - how can I trigger the page reload if
$(this).data('seconds')
has 0?
Thanks for reply :)