Skip to content

Instantly share code, notes, and snippets.

@felix-d
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felix-d/ad6ac4a8cebda897e7c5 to your computer and use it in GitHub Desktop.
Save felix-d/ad6ac4a8cebda897e7c5 to your computer and use it in GitHub Desktop.
Function for jquery to set divs to the same height, using the max height of those divs.
//Author: Felix Descoteaux
//Usage: $.sameheight($("#element1"), $(".element2"), ... );
(function($) {
var sameHeight = function sameHeight() {
var arrayOfHeights = [],
arr = Array.prototype.slice.call(arguments),
max;
//Clear any height value
arr.forEach(function(e) {
e.height("");
});
//Push outerHeight in array
arr.forEach(function(e) {
arrayOfHeights.push(e.outerHeight());
});
//Set max
max = Math.max.apply(null, arrayOfHeights);
//Set css
arr.forEach(function(entry) {
entry.css({
position: "relative",
height: max
});
});
};
//Set function
$.sameHeight = sameHeight;
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment