In my project there could be any amount of divs like a thousand, two thousand, a million etc.. I want their background colors to go from green to red. so they all get a different shade of color. the first div will be "real" green the last div will be "real" red.
Here is what I have. As you can see there are divs at the end that get left without a background-color. I would prefer to solve this using rgb.
$(function(){
var r = 20;
var g = 200;
var b = 10;
for(var i = 0; i < 300; i++){
$("body").append("<div class = 'box'>");
}
$(".box").each(function(){
if(g > 0 && r < 255){
$(this).css("background", "rgb("+ r + ","+ g + ","+ b + ")");
g-=1;
r+=1;
}
})
})
.box{
border:2px solid black;
margin: 10px;
width: 20%;
height: 100px;
float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>