0

This is my current code, I'm trying to set the background of my site to a rainbow gradient however this code isn't working, however I know its being called as the alert goes off on the page? How would I go about fixing this?

var date = new Date();
var hours = date.getHours();
var day = date.getDay();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var month = date.getMonth();

if (month == 4) {
    document.getElementById("container").style.backgroundColor = `linear-gradient(red, yellow, green)`;
    alert("test");
}
Kevin D
  • 3
  • 3
  • 1
    Use `style.backgroundImage ` – 0stone0 May 31 '21 at 21:20
  • Does this answer your question? [Adding CSS Gradient as Background Image Programatically](https://stackoverflow.com/questions/36524156/adding-css-gradient-as-background-image-programatically) – 0stone0 May 31 '21 at 21:22
  • From MDN: creates an image consisting of a progressive transition between two or more colors along a straight line. Its result is an object of the data type, which is a special kind of – dale landry May 31 '21 at 21:25

1 Answers1

0

Use el.style.background not backgroundColor.

See examples here: MDN linear-gradient()

var date = new Date();
var hours = date.getHours();
var day = date.getDay();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var month = date.getMonth();

if (month == 4) {
    document.getElementById("container").style.background = `linear-gradient(red, yellow, green)`;
}
#container {
  width: 500px;
  height: 500px;
}
<div id="container"></div>
dale landry
  • 7,831
  • 2
  • 16
  • 28