Simple JavaScript Countdown

There are many jQuery countdown plugins available, but I couldn’t find just the countdown function. So here it is, customize it the way you want 🙂

var countdown = function (callback, duration) {
   var container = $(this[0]);
   var countdown = setInterval(function () {
      if (--duration) {
        h=("0"+Math.floor(duration/3600)).slice(-2);
        m=("0"+Math.floor(duration/60)).slice(-2);
        s=("0"+duration%60).slice(-2);
        container.html(h+':'+m+':'+s);
      } else {
        clearInterval(countdown);
        callback.call(container);
      }
   }, 1000);
};

You can remove the hour (var h) or add a day counter with

d=("0"+Math.floor(duration/86400)).slice(-2);
...
container.html(d+':'+h+':'+m+':'+s);

You can style them by applying classes in this line
container.html(h+':'+m+':'+s);

Example on JSFiddle: http://jsfiddle.net/shoobm/erugvzub/

Have fun!