Im using this javascript countdown plugin and I want to detect the finish date, here's my set up and so far what i've tried.
$('#countdown').countdown('2015/11/12', function(event) {
$(this).html(event.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
}).on('finish.countdown', function(event){
alert("the event is finish");
});
but seems doesn't work, any ideas, help please?
You are using the 'legacy approach' and as the documentation says:
With the legacy approach you will need to handle all events in a single callback (update, finish or stop) through the event.type property
You should use the newer method:
$('#countdown').countdown('2015/11/12')
.on('update.countdown', function(e) {
$(this).html(e.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
})
.on('finish.countdown', function(e) {
alert("the event is finish");
});
Or if you still want to use the older syntax:
$('#countdown').countdown('2015/11/12', function(event) {
if (event.type === 'update.countdown') {
$(this).html(event.strftime('<div id="countdown_container"><div class="countdown_wrap weeks">%w weeks</div><div class="countdown_wrap days">%d days</div><div class="countdown_wrap hours">%H:%M:%S</div>'));
} else if (event.type === 'finish.countdown') {
alert("the event is finish");
});