I have a function
function giveTheseEqualHeight ( selector )
{
// selector: CSS selector of elements on the page to be forced to have the same height
var these = $(selector);
if (these.length < 2) return;
these.height('auto');
var maxHeight = these.first().height();
these.each(function(){
var thisHeight = $(this).height();
if (thisHeight > maxHeight) maxHeight = thisHeight;
});
these.height(maxHeight);
}
which is very self explanatory.
Example use case:
giveTheseEqualHeight('.service-column h3');
would make all h3
elements that are descendants of elements of class service-column
have equal height by heightening the ones that are smaller than the one with the most height.
The problem is that the loop
these.each(function(){
var thisHeight = $(this).height();
if (thisHeight > maxHeight) maxHeight = thisHeight;
});
doesn't need to execute its body on the first iteration -- such amounts to useless operations. Instead of these.each
, I want to start with the 2nd item. Is this possible?