16
I created a function that changes colors (pulled from one array) on certain page elements (which are also on array), but it was very strange, as it changes the colors of the elements one after the other. I wanted to do something different, like: Draw the element and the color that will be modified. How I adapt my function to do this?
Example -> http://jsbin.com/citoq/1/watch?output
window.onload = function(){
var box = document.getElementsByClassName('box');
var background = ["#f36", "#C3C", "#fc0", "#FC6", "#9C0"];
cor=0;
div=0;
setInterval(function(){
box.item(div).style.backgroundColor = background[cor];
cor++; div++;
if(cor>=background.length){
cor=0;}
if(div>=box.length){
div=0;}
},2000)
}
You want colors to appear from this vector of "random"?
– Felipe Avelar
Yes, I want both colors, as many elements to be randomly exchanged
– Odair
You can check out here your answer
– Erlon Charles
Thank you @Erloncharles!
– Odair