Skip to content

Instantly share code, notes, and snippets.

@felix-d felix-d/sameheight.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.