var $divs = $('.container .sub'); var arrOffsetTops = []; $divs.each(function(index,element){ arrOffsetTops[index]=element.position().top; arrOffsetTops[index].newLine = (index==0 ? true : false); if(index > 0) { if(arrOffsetTops[index] > arrOffsetTops[index-1]) { // it on another line arrOffsetTops[index].newLine = true; } } });
Then you can loop through the array with index and check for .newLine == true to do whatever you need to do with the div.
UPDATE:
An example of how you could use this:
var divCount = $divs.length; for(var i=0; i<divCount; i++) { if(true == arrOffsetTops[ i ].newLine) { $divs.eq( i ).addClass('newline-marker'); } } .newline-marker { -webkit-box-shadow:0 0 10px black; -khtml-box-shadow:0 0 10px black; -moz-box-shadow:0 0 10px black; -o-box-shadow:0 0 10px black; -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=0, Color='#000000')"; filter: progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=0, Color='#000000'); box-shadow:0 0 10px black; zoom:1; }
source share