$('.row').slice(0, 3).css('background-color: green');
$('.row').slice(4, 6).css('background-color: yellow');
$('.row').slice(6, 10).css('background-color: green');
Or
x = 0;
$('.row').each(function() {
if (x >= 0 && x <= 3) {
$(this).css('background-color: green');
}
if (x >= 4 && x <= 6) {
$(this).css('background-color: yellow');
}
if (x >= 6 && x <= 10) {
$(this).css('background-color: green');
}
x++;
});
Is one faster than the other?
Use slice. Each does comparisons on every iteration. Slice will just take the columns. Plus slice expresses the intention better – this will allow for better optimization (if any) and code is a lot more readable.