var ar = ["one_in", "two_in", "three_in"];
var colors = {};
[ar[0]] = 'blue';
[ar[1]] = 'green';
[ar[2]] = 'red';
x = document.getElementsByTagName('DIV');
for (var i = 0 ; i < x.length ; i++ ){
x[i].style.backgroundColor = colors[x[i].className];
}
.one_in,.two_in{
width:100px;
height:100px;
border:1px solid #000;
}
<div class="one_in"></div><div class="two_in"></div>
Run codeHide resultwhy not continue this work, I want the div to be colored with the appropriate colors and div class, as mentioned in the array and the object, I know this is a simple question for you, there may be a small mistake
https://jsfiddle.net/qothk6g3/3/
source
share