Reputation: 69
I'm working on a countdown right now. The goal is to display multiple countdowns on a page. One countdown with an interval() is not a problem, but when it gets to two or more countdowns it will only display the last countdown.
Countdown structure:
<div value"..."> <div>
.html()
or .text()
Hope you can help me out.
Upvotes: 0
Views: 60
Reputation: 9
If you don't need to keep the original value you can also use something like this:
$(".timestamp").each(function() {
var timestamp_value = $(this).attr("value");
var new_value = timestamp_value - 1;
//change how you want your time look like below
var new_value_text = new_value.toString();
$(this).attr("value", new_value);
$(this).html(new_value_text);
});
put it in a function and then use setInterval. Demo link below:
Upvotes: 1
Reputation: 2967
try changing:
$(".timestamp").text(function(k){
return seconds[k];
});
with:
$(this).text(seconds[k]);
Upvotes: 1