$('a').each(function(i){ i = Math.ceil(++i/4); var color = i == 1 //first 4 ? 'red' : i == 2 //other 4 ? 'blue' : i == 3 ? 'yellow' : // etc i == 4 ? 'green' : 'lime'; $(this).css('backgroundColor', color); });
On Jan 22, 11:37 pm, devilmike <devilm...@gmail.com> wrote: > Hello all, > > I can't quite get my head around how to accomplish this and any > guidance would be greatly appreciated. > > Say I have some random number of <h1>'s on the page, like 20. I'd like > to grab the first 4 and make them red, then grab the next 4 and make > them blue, then grab the next 4 and do something else with them, and > so on until I reach the end. > > I've been looking at .each() and some of the array functions, but I > can't seem to piece it together. > > Thanks, > Michael