[jQuery] Re: change certain elements in result set based on position

2009-01-26 Thread Ricardo Tomasi
You can loop over the colors also just by using the modulo operator instead: $('a').each(function(i){ i = ++i % 4; var color = i == 1 ? 'red' : //first 4 i == 2 ? 'blue' : //second group of 4 i == 3 ? 'yellow' : // third group 'lime'; //fourth group and so on $(th

[jQuery] Re: change certain elements in result set based on position

2009-01-23 Thread devilmike
Awesome Ricardo, thanks! I guess the only issue I have is that I'll never know how many "sets of 4" I'll be dealing with, and i apologize for not explaining myself very well in my example. Basically for each "set", I want to run the same function. This is what I came up with. It works, but I'm a

[jQuery] Re: change certain elements in result set based on position

2009-01-23 Thread Ricardo Tomasi
$('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 wrote: > Hell