I have a div with several boxes within while loop. I want to give the two alternative div background color. For first 3 boxes i have to give the first color. Then for next 3 boxes i’v to give next color, then again for the next 3 boxes i’v to give the first color and so on.
Clearly i want to give the two colors alternatively for 3 boxes alternatively from first. Can anyone help me for this.
Advertisement
Answer
var count=0; $("div").each(function (i) { count++; if (count%3) { this.style.color = "blue"; } else { this.style.color = "black"; } });