Skip to content

Instantly share code, notes, and snippets.

@ashhitch
Created April 30, 2014 10:05
Show Gist options
  • Select an option

  • Save ashhitch/01958abd23c1e31bc5c9 to your computer and use it in GitHub Desktop.

Select an option

Save ashhitch/01958abd23c1e31bc5c9 to your computer and use it in GitHub Desktop.
Function to make all elements within a wrapper, the same height with jQuery.
function checkAllHeights(row, item) {
if ($(row).length !== 0) {
var itemHeight = 0;
//reset size
$(row + ' ' + item).removeAttr('style');
//Check heights to get tallest
$(row + ' ' + item).each(function (index) {
if (($(this).height() > itemHeight)) {
itemHeight = $(this).height();
}
}).promise().done(function () {
//Once done set all to the highest
$(row + ' ' + item).height(itemHeight);
});
}
}
//onLoad
$(window).load(checkAllHeights('.row-class', '.item-class'));
//onResize
$(window).resize(checkAllHeights('.row-class', '.item-class'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment