I made a live clock on my homepage. Now i want to change the color of my #nav div to black when its after 6 o clock. I have this code but it doesnt work. The clock does, but the background color change doesnt
function maakTijd() {
var Tijd = new Date();
var h = Tijd.getHours();
var m = Tijd.getMinutes();
var s = Tijd.getSeconds();
setTimeout('maakTijd()',1000);
if (h < 10){
h = "0"+ h;
}
if (m < 10){
m = "0"+ m;
}
if (s < 10){
s = "0"+ s;
}
var klok = document.getElementById('hometext');
klok.textContent = h + ":" + m + ":" + s;
klok.innerText = h + ":" + m + ":" + s;
// the code above is the clock
if (h > 18 && h < 6) //here i set the time and the if statement
{
document.getElementById("hometext").style.backgroundColor = "black";
}
}
maakTijd();
h cannot be greater than 18 and less than 6 at the same time...
Instead of this:
Use this:
You probably want Or here instead of And.