skip to Main Content

When i run this code i get an error saying its reading null from .style which dosent make any sense to me because im assigning it an value not reading it.

function colorChange() {
  document.body.style.background = "rgb(29, 33, 240);";
}

setInterval(colorChange, 1);

2

Answers


  1. document.body.style.backgroundColor = "red";

    just use this line then you can see your element color has changed….

    Login or Signup to reply.
  2. You need to remove the semicolon after the rgb for it to work, as you’re assigning a value, not writing a complete CSS statement. Also, your setInterval isn’t really doing anything (it just perpetually sets the background color to a semi-blue color every millisecond).

    function colorChange() {
      document.body.style.background = "rgb(29, 33, 240)";
    }
    
    colorChange();
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search