I usually don't like to post about subjects I'm not to familiar with (working with time and dates in javascript has always been a weakness of mine), but I am in desperate need of some help.
I'm using this link to display a countdown timer on clients website. It should be pretty straight forward, right? I implemented it like this:
<script type="text/javascript">
// set the date we're counting down to
var target_date = new Date('Sep, 18, 2015').getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById('countdown');
// update the tag with id "countdown" every 1 second
setInterval(function () {
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
// format countdown string + set tag value
countdown.innerHTML = '<span class="days">' + days + ' <b>Days</b></span> <span class="hours">' + hours + ' <b>Hours</b></span> <span class="minutes">'
+ minutes + ' <b>Minutes</b></span> <span class="seconds">' + seconds + ' <b>Seconds</b></span>';
}, 1000);
</script>
Style
<style>
.container {
margin: 0px auto;
padding: 0px;
}
#main {
background: #3B3B3B;
height: 430px;
}
.content {
padding: 10px 44px;
}
.text {
border-bottom: 1px solid #262626;
margin-top: 40px;
padding-bottom: 40px;
text-align: center;
}
.text h2 {
color: #E5E5E5;
font-size: 30px;
font-style: normal;
font-variant: normal;
font-weight: lighter;
letter-spacing: 2px;
}
.counter {
background: #2C2C2C;
-moz-box-shadow: inset 0 0 5px #000000;
-webkit-box-shadow: inset 0 0 5px #000000;
box-shadow: inset 0 0 5px #000000;
min-height: 150px;
text-align: center;
}
.counter h3 {
color: #E5E5E5;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: lighter;
letter-spacing: 1px;
padding-top: 20px;
margin-bottom: 30px;
}
#countdown {
color: #FFFFFF;
}
#countdown span {
color: #E5E5E5;
font-size: 26px;
font-weight: normal;
margin-left: 20px;
margin-right: 20px;
text-align: center;
}
</style>
HTML
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div id="main">
<div class="content">
<div class="text">
<h2>This Website Is Under Construction</h2>
</div> <!-- /.Text Div -->
<div class="counter">
<h3>Estimated Time Remaining Before Launch:</h3>
<div id="countdown">
</div><!-- /#Countdown Div -->
</div> <!-- /.Counter Div -->
</div> <!-- /.Content Div -->
</div> <!-- /#Main Div -->
</div> <!-- /.Columns Div -->
</div> <!-- /.Row Div -->
</div> <!-- /.Container Div -->
Output
Firefox gives me the following error:
Chrome tells me the following:
The code is implemented exactly as above but I am getting the errors as shown in above images. However, in this fiddle I have created it is working. Weird, why is this?