I have six div's on a page that each have the same class. I am trying to assign each of them one unique color that I have chosen in an array. I don't want any of them to have the same color.
I've successfully assigned each of the divs a background color from an array, however, some of the classes can get the same background color since its currently just choosing the color randomly from the array.
jQuery(document).ready(function($) {
$(".et_pb_post").each(function() {
var colors = ["#CFEAEA ","#c9e3d5","#e7dadd","#dde9eb","#ecfac7","#facba9","#dfdbd3","#f1fdc1"];
var rand = Math.floor(Math.random()*colors.length);
$(this).css("background-color", colors[rand]);
});
});
and then the html is something like
<div class="et_pb_post">Some content with bg-color A</div>
<div class="et_pb_post">Some content with bg-color B</div>
<div class="et_pb_post">Some content with bg-color C</div>
<div class="et_pb_post">Some content with bg-color D</div>
How do I make sure all of the background-colors are unique?
Thanks a lot!