-2
var lights = ("blue", "white", "violet");

function check() {

for(var i = 0; i <= lights.length; i++) {
    if(i = "blue") {

  } else if (i = "white") {

  } else if (i = "violet") {

  }
}

I need help, I want to be able to change a css property which is not listed here but it consists of background colour is blue and I want to change it to another colour while accessing javascript. If anyone knows, please can they tell me step by step what to do please, thank you

cpuneeded
  • 1
  • 1
  • 1

2 Answers2

3

If you want to use pure Javascript you can use something like this to set a background color for an element:

document.getElementById("myDiv").style.backgroundColor = "blue";
Aram
  • 5,537
  • 2
  • 30
  • 41
1

There are a couple of ways to change a CSS property of an element. Both methods require accessing HTML DOM elements by ID or class.

Classic Javascript:

document.getElementById('someID').style.backgroundColor = "blue";

jQuery:

$('#someID').css('backgroundColor', 'blue');