I have divs that are loaded from a database, the number of divs is not known ( may increase or decrease ) , each div have a random color from my code :
$(".ooicon").each(function() {
var items = ["#9062aa","#3fb4e9","#6fc063","#d94949","#f8951e","#7a564a","#029688","#2d2f79","#e81f63"];
var color = items[Math.floor(Math.random() * items.length)];
$(this).css('background', color);
});
this code gives a random color changed on each reload or refresh , I want to make the colors static and not changed on refresh,
for example the first div will have the color #9062aa from the code, the second will be #3fb4e9 and so on.. when the colors in the array reach the last, it start over again with the first color.
I hope you understand me.
var color = items[index % items.length];indexis passed as an argument to the callback function ofeach.