0

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/

1
  • You can't just put a value attribute on a <div> element like that... Use at least an hidden input no ? Or a data- attribute Commented Jan 23, 2015 at 14:24

2 Answers 2

1

try changing:

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

with:

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

demo here

Sign up to request clarification or add additional context in comments.

Comments

1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.