Hi I am trying to add multiple countdown timer through javascript but some how, its not working , Can any one tell me what I am doing wrong, I am a new bee.
below is by code:
php while loop {
<script>
var timer;
var days= <?php echo $datediff ; ?>;
var compareDate = new Date();
compareDate.setDate(compareDate.getDate() + <?php echo $datediff ?> ); //just for this demo today + 7 days
timer = setInterval(function() {
timeBetweenDates(compareDate);
}, 1000);
function timeBetweenDates(toDate) {
var dateEntered = toDate;
var now = new Date();
var difference = dateEntered.getTime() - now.getTime();
if (difference <= 0) {
// Timer done
clearInterval(timer);
} else {
var seconds = Math.floor(difference / 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;
$(".days") .text(days);
$(".hours").text(hours);
$(".minutes").text(minutes);
$(".seconds").text(seconds);
}
}
</script>
<div class="timer">
<span class="days"></span>days
<span class="hours"></span>hours
<span class="minutes"></span>minutes
<span class="seconds"></span>seconds
</div>
I am not able to get the timer work have changed the id to class.