Skip to content

Instantly share code, notes, and snippets.

@dakshhmehta
Created July 1, 2017 09:56
Show Gist options
  • Save dakshhmehta/e91e21beaaa3c99e5fd24165eea86342 to your computer and use it in GitHub Desktop.
Save dakshhmehta/e91e21beaaa3c99e5fd24165eea86342 to your computer and use it in GitHub Desktop.
Fixes the heights of all children to same one.
/**
Usage:
<div class="row same-height" data-class="col-md-4">
<div class="col-md-4"><p></p></div>
<div class="col-md-4"><p></p><p></p></div>
<div class="col-md-4"><p></p></div>
<div class="col-md-4"><p></p></div>
</div>
All columns will have height similar to second column as It has highest height amount all of them.
**/
var max_height = 0;
$(".same-height").each(function(){
var className = $(this).data('class');
if(className){
$(this).children('.'+className).each(function(){
if(max_height < $(this).height()){
max_height = $(this).height();
}
});
}
if(className){
$(this).children('.'+className).each(function(){
$(this).height(max_height);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment