Last active
August 29, 2015 14:15
-
-
Save bgaeddert/3ac60fb2813ee8766ade to your computer and use it in GitHub Desktop.
Equalize element heights with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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