Skip to content

Instantly share code, notes, and snippets.

@bgaeddert
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save bgaeddert/3ac60fb2813ee8766ade to your computer and use it in GitHub Desktop.

Select an option

Save bgaeddert/3ac60fb2813ee8766ade to your computer and use it in GitHub Desktop.
Equalize element heights with jQuery
// For use with jQuery
// Example
equalize_heights('.row .box')
// This will make all the .box elements the same height.
function equalize_heights(elem){
// Get an array of all element heights
var elementHeights = $(elem).map(function() {
return $(this).height();
}).get();
// Math.max takes a variable number of arguments
// `apply` is equivalent to passing each height as an argument
var maxHeight = Math.max.apply(null, elementHeights);
// Set each height to the max height
$(elem).height(maxHeight);
return $(elem);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment