Qamelion
Qamelion

Reputation: 69

Problems with (multiple) jQuery countdowns

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:

  1. Grab the unix timestamp from <div value"..."> <div>
  2. Turn unix timestamp with jQuery to a nice countdown.
  3. Display all countdowns on the page with .html() or .text()

Hope you can help me out.

http://jsfiddle.net/be89dwno/

Upvotes: 0

Views: 60

Answers (2)

kocu
kocu

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:

http://jsfiddle.net/x6htakaw/

Upvotes: 1

pumpkinzzz
pumpkinzzz

Reputation: 2967

try changing:

$(".timestamp").text(function(k){
    return seconds[k];
});

with:

$(this).text(seconds[k]);

demo here

Upvotes: 1

Related Questions