0

I'm doing a Bingo without JQuery. When I generate a number, the programm change the background-color to red.

var elems = document.getElementsByClassName(random1);
for(var m = 0; m < elems.length; m++) {
    elems[m].style.backgroundColor = 'red';
}

Is possible check if the div has background color?

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Alexandre Velo
  • 115
  • 1
  • 10
  • 1
    why don't you use the same way you're assigning color to an element to check it ? `if(elems[m].style.backgroundColor)` or you can do an explicit check if it's not red or empty - `element.style.backgroundColor !== 'red'` – Arkantos Feb 27 '16 at 11:57
  • oh god, I forget the third symbol of comparasion – Alexandre Velo Feb 27 '16 at 12:01
  • @Arkantos - what if the original background colour is set via the style sheet? – nnnnnn Feb 27 '16 at 12:08
  • @nnnnnn.. I forgot that this won't work for styles set via style sheets. @Alexandre.. you can refer to this [link](http://stackoverflow.com/questions/6338217/get-a-css-value-with-javascript) for options like `getComputedStyle()` – Arkantos Feb 27 '16 at 13:10

0 Answers0