0

I am getting an output of 00 min NaN sec. Does anyone know what may be wrong with my code?

Desired outcome, countdown from 5min then add class 'ended'

using jquery.countdown.js

Thank you.

$(function() {
        var endDate = "05:00";

        $('.countdown.callback').countdown({
          date: endDate,
          render: function(data) {
            $(this.el).html("<div>" + this.leadingZeros(data.min, 2) + " <span>min</span></div><div>" + this.leadingZeros(data.sec, 2) + " <span>sec</span></div>");
          },
          onEnd: function() {
            $(this.el).addClass('ended');
          }
        }).on("click", function() {
          $(this).removeClass('ended').data('countdown').update(endDate).start();
        });

      });

1 Answer 1

1

If I recall correctly, your endDate variable is not valid. I believe it needs to follow the JavaScript method of getting a date so you might need to do something like this

var endDate = new Date();
endDate.setMinutes(endDate.getMinutes() + 5); // Adding 5 minutes to the current time
Sign up to request clarification or add additional context in comments.

4 Comments

Ok, but now the on.Click function isnt refreshing the countdown
You will need to do endDate = new Date(); endDate.setMinutes(endDate.getMinutes() + 5); inside of the on click event but before $(this).removeClass line.
.on("click", function() { endDate = new Date(); endDate.setMinutes(endDate.getMinutes() + 5); $(this).removeClass('ended'); });
.on("click", function() { endDate = new Date(); endDate.setMinutes(endDate.getMinutes() + 5); $(this).removeClass('ended'); $(this).removeClass('ended').data('countdown').update(endDate).start(); });

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.