Skip to content

Instantly share code, notes, and snippets.

@lutsen
Last active December 28, 2015 02:39
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 lutsen/7429372 to your computer and use it in GitHub Desktop.
Save lutsen/7429372 to your computer and use it in GitHub Desktop.
Get highest element of a class of each containing parent element, and give all elements in this parent element this height. Uses jQuery.
function sameHeight(target) {
// Reset
$(target).each(function() {
$(this).parent().data('height', 0);
});
// Get highest element of each containing parent element
$(target).each(function() {
if ($(this).parent().data('height') < $(this).height()) {
$(this).parent().data('height', $(this).height());
}
});
// Give all elements in a parent the same maximum height
$(target).each(function() {
$(this).height(
$(this).parent().data('height')
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment