I've been struggling with this issue for more than 4 hours now. None of the solutions provided on Stack Overflow seem to work for me. Here's the code snippet I've been working on:
<html>
<head>
<style>
.day {
background-image: url(test2.png);
}
.night {
background-image: url(test.png);
}
</style>
</head>
<body class="day" class="night">
<script>
setInterval(function() {
var d = new Date();
var n = d.getHours();
if (n > 23 || n < 6) {
document.body.className = "night";
} else {
document.body.className = "day";
}
console.log("test");
}, 1000 * 60 * 60);
</script>
</body>
</html>
My goal is to have the night background displayed from 11 PM to 7 AM, and the day background shown at other times.
I'm using placeholder images as the actual pictures contain mild graphic content. Please feel free to replace them with your own test images.