You basically need to loop over all the .item
elements and do pretty much the logic you had already.
$(function(){
$('.item').each(function(){
var $item = $(this);
var top = parseInt($item.css('top'),10);
if ( top < 1 ) {
$item.find('.overlay').css('background','#ff3366');
}
if ( top > 1 ) {
$item.find('.overlay').css('background','#0099ff');
}
})
});
JsFiddle: http://jsfiddle.net/6tRwV/2/
as with all things jQuery, there is usually a shorter way:
$(function(){
$('.overlay').css('background',function(){
var top = parseInt($(this).parent().css('top'),10);
return top<1 ? '#ff3366' : '#0099ff';
});
});
jsFiddle: http://jsfiddle.net/6tRwV/3/