Reputation: 71
I've looked several places for an answer, but even though I've found people with similar problems, the solutions they got did not help me sadly.
I have a JS in my header, that wont load when the page loads. The body is running an onload for the function ShowTime but that doesn't work either, same for the document.ready. Im slowly getting frustrated, so I came here for help. I've tested it in jsfiddle where it works just fine, just not in my browser.
The script:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
function ShowTime()
{
var now = new Date();
var hrs = 15-now.getHours();
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = "" +hrs+' hours '+mins+' minutes '+secs+' seconds';
$("#countdown").html(timeLeft);
}
var countdown;
function StopTime()
{
clearInterval(countdown);
}
ShowTime();
var countdown = setInterval(ShowTime ,1000);
</script>
HTML:
<div id="countdown"></div>
Any help would be greatly appreciated.
Upvotes: 1
Views: 1755
Reputation: 9992
It's working just you close <script>
wrong
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
function ShowTime()
{
var now = new Date();
var hrs = 15-now.getHours();
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
timeLeft = "" +hrs+' hours '+mins+' minutes '+secs+' seconds';
$("#countdown").html(timeLeft);
}
var countdown;
function StopTime()
{
clearInterval(countdown);
}
ShowTime();
var countdown = setInterval(ShowTime ,1000);
});
</script>
Upvotes: 3