I have this function to assign the same color choosen randomly from an array to all elements with the same class but the elements get different colors at same time. Now the function works but each h2 element get different color. I would like to have that all the h2 element with "change_color" class get the same color every time.
jQuery(document).ready(function() {
var colors = ["#FFB24A", "#ED145B", "#55D3D2", "#E8390F", "#787878"];
jQuery(".change_color h2").each(function() {
jQuery(this).css("color", colors[Math.floor(Math.random() * colors.length)]);
});
});
What do I need to change to apply the same color to all the elements? Thank you.
Aucun commentaire:
Enregistrer un commentaire