My goal is for every div with class "main" to have a random background color. I have a script that generates random color, but using jquery, I can just apply it to all divs in the class. How can I select a div, apply a color, select the next div in the class, create a new random color, apply it and repeat? Here is my code:
$(document).ready(function() {
var hue = 'rgb(' + (Math.floor((256-199)*Math.random()) + 200) + ','
+ (Math.floor((256-199)*Math.random()) + 200) + ','
+ (Math.floor((256-199)*Math.random()) + 200) + ')';
$('.main').css("background-color", hue);
});
user186053
source
share