Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Countdown plugin restart

I'm using the jQuery Countdown plugin (http://keith-wood.name/countdown.html), but I can't seem to reset the timer.

When a button is clicked the folowing function starts the countdown:

function startResetCounter() {
    $('.reset_counter div').countdown({ 
        until: '+3m +0s',
        compact: true,
        format: 'MS',
        onExpiry: resetPage
    });
}

But when I reclick the button it won't reset the timer.

Anyone who can help me out?

like image 744
timG Avatar asked Mar 08 '26 11:03

timG


1 Answers

Add on top of startResetCounter function following line:

$('.reset_counter div').countdown('destroy'); //remove countdown if it was already used

so at the end you will end up with:

function startResetCounter() {
    $('.reset_counter div').countdown('destroy');

    $('.reset_counter div').countdown({ 
       until: '+3m +0s',
       compact: true,
       format: 'MS',
       onExpiry: resetPage
    });
}
like image 147
jasin_89 Avatar answered Mar 10 '26 02:03

jasin_89