(function($){ $.fn.equalBlocks = function() { var tallest = 0, rowStart = 0, items = [], $el, topPos = 0; $(this).each(function() { $el = $(this); topPos = $el.position().top; if (rowStart != topPos) { // we just came to a new row. Set all the heights on the completed row for (i = 0 ; i < items.length ; i++) { items[i].height(tallest); } // set the variables for the new row items.length = 0; // empty the array rowStart = topPos; tallest = $el.height(); items.push($el); } else { // another item on the current row. Add it to the list and check if it's taller items.push($el); tallest = Math.max(tallest, $el.height()); } // do the last row for (i = 0 ; i < items.length ; i++) { items[i].height(tallest); } }); } })(jQuery);