Meghdeep Ray
Meghdeep Ray

Reputation: 5537

How to trigger event on countdown in JQuery?

I'm using - http://github.com/rendro/countdown/
To do the countdown, the JS to execute it is :

$( function() 
{
// Add background image
    $.backstretch('images/road2.jpg');
    var endDate = "December  17, 2015 11:33:00";
    $('.countdown.simple').countdown({ date: endDate });
    $('.countdown.styled').countdown(
    {
      date: endDate,
      render: function(data) 
      {
        $(this.el).html("<div>" + this.leadingZeros(data.days, 3) + " <span>days</span></div><div>" + this.leadingZeros(data.hours, 2) + " <span>hrs</span></div><div>" + this.leadingZeros(data.min, 2) + " <span>min</span></div><div>" + this.leadingZeros(data.sec, 2) + " <span>sec</span></div>");
      }
    });
    $('.countdown.callback').countdown({
      date: +(new Date) + 10000,
      render: function(data) 
      {
        $(this.el).text(this.leadingZeros(data.sec, 2) + " sec");
      },
      onEnd: function() 
      {
        alert("Done");
        $(this.el).addClass('ended');
      }
    }).on("click", function() 
    {
      $(this).removeClass('ended').data('countdown').update(+(new Date) + 10000).start();
    });

});


The countdown works every time but I never get the alert I'm trying to get.
How can I get an event to trigger on the ending of the countdown ?

Upvotes: 0

Views: 966

Answers (1)

Batu.Khan
Batu.Khan

Reputation: 3065

Your onEnd callback is misplaced. Do it like this

 $('.countdown.simple').countdown({ date: endDate,
      onEnd: function() 
      {
        alert("Done");
        $(this.el).addClass('ended');
      } 
 });

Upvotes: 1

Related Questions