I'm struggling to change my HTML background based on the date. The code I've tried isn't working as expected and I can't seem to find any relevant examples to guide me.
My goal is simple - I want the background of my HTML page to be changed whenever a new season begins by swapping out the image defined in my CSS file.
Here's what I have so far:
var d = new Date();
var day = d.getDate();
var month = d.getMonth();
if (month >= 0 && month <= 2) {
document.background-image: url("springTree.jpg");
} else if (month >= 3 && month <= 5) {
document.background-image: url("summerTree.jpg");
} else if { (month >= 6 && month <= 8)
document.background-image: url("autumnTree.jpg");
} else if (month >= 9 && month <= 11) {
document.background-image: url("winterTree.jpg");
This is how my CSS looks:
div.body {
background-image: url("summertree.jpg");
width: 640px;
height: 1136px;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: cover;
}
I'm open to trying JQuery or any other suggestions to achieve this effect because, frankly, I feel quite lost on how to make it work. Any assistance would be greatly appreciated. Thanks!