Skip to content

Instantly share code, notes, and snippets.

@filipecsweb
Last active October 12, 2016 08:49
Show Gist options
  • Save filipecsweb/9c3649c7c8e4f8ed3d3e to your computer and use it in GitHub Desktop.
Save filipecsweb/9c3649c7c8e4f8ed3d3e to your computer and use it in GitHub Desktop.
Forcing the same height to specific elements
/**
* Define parameters to set 'where' and what 'element' will have same height.
*
* @author Filipe Seabra
* @param where element's father
* @param element selector of the elements that must have same height
*/
jQuery(window).load(function(){
function sameHeight(where, element){
var height = [];
var maxHeight = 0;
jQuery(where).find(element).each(function(index){
height[index] = jQuery(this).height();
if(height[index] > maxHeight){
maxHeight = height[index];
}
}).css('min-height', maxHeight);
}
sameHeight('.where', 'div.element'); // Just an example
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment