0

I want to change the background color of a class named "Zones" to blue and i've tried:

document.getElementsByClassName("Zones").style.backgroundColor = "blue";

But it's for some reason not working...

1 Answers1

3

If there is only one class, you can do this:

document.getElementsByClassName("Zones")[0].style.backgroundColor = "blue";

If there is more than 1 class, you can do this:

var zonesLength = document.getElementsByClassName.length;

for(i = 0; zonesLength < i; i++) {
    document.getElementsByClassName("Zones")[i].style.backgroundColor = "blue";
}
Albzi
  • 15,431
  • 6
  • 46
  • 63