You can loop with .slice() to scroll in sets 2, for example:
var elems = $("div.large"); for(var i = 0; i < elems.length; i+=2) { var divs = elems.slice(i, i+2), height = Math.max(divs.eq(0).height(), divs.eq(1).height()); divs.css('min-height', height); }
Or, for a more general approach, since you want to do this with 3, and here is the plugin form:
$.fn.setMinHeight = function(setCount) { for(var i = 0; i < this.length; i+=setCount) { var curSet = this.slice(i, i+setCount), height = 0; curSet.each(function() { height = Math.max(height, $(this).height()); }) .css('min-height', height); } return this; };
Then you can call it like this:
$("div.large").setMinHeight(2);
Here you can check it out .
source share