Issue on Updating jQuery setTimeout()
I am trying to make a simple plugin to calculate date and time by this code:
- $.fn.timeCounter = function(time) {
-
- var target = new Date(time);
- var now = new Date();
- var timeDiff = target.getTime() - now.getTime();
- if (timeDiff <= 0) {
- clearTimeout(timer);
- }
- var seconds = Math.floor(timeDiff / 1000);
- var minutes = Math.floor(seconds / 60);
- var hours = Math.floor(minutes / 60);
- var days = Math.floor(hours / 24);
- hours %= 24;
- minutes %= 60;
- seconds %= 60;
-
- $("#timer").append( "<p>"+days+"</p>" );
- $("#timer").append( "<p>"+hours+"</p>" );
- $("#timer").append( "<p>"+minutes+"</p>" );
- $("#timer").append( "<p>"+seconds+"</p>" );
- var timer = setTimeout(timeCounter,1000);
- };
- $("#timer").timeCounter("june 16, 2014 00:01:00");
the code is working fine but I am having problem on displaying actual count down on numbers! can you please let me know how to fix this?