I know this question has been asked a million times but i\'m looking for something more specific.
As my site is fully responsive I need the divs to be resized based
I took dclawson's excellent answer and made some edits so it works in other situations, particularly with nested elements as is commen in bootstrap rows.
$.fn.resEqHeight = function(options) {
var defaults = {
child: false
};
var options = $.extend(defaults, options);
var $el = $(this);
if ($el.length > 0) {
if(!$el.data('resEqHeight')) {
$(window).bind('resize.resEqHeight', function () {
$el.resEqHeight(options);
});
$el.data('resEqHeight', true);
}
} else {
console.log("No items found for resEqHeight.");
}
if( options.child && options.child.length > 0 ){
var elmtns = $(options.child, this);
} else {
var elmtns = $(this).children();
}
var prevTop = 0;
var max_height = 0;
var elements = [];
elmtns
.height('auto')
.each(function() { $(this).data('resEqHeight.top', $(this).offset().top ); })
.each(function(index) {
var $el2 = $(this);
var thisTop = $el2.data('resEqHeight.top');
if (index > 0 && prevTop != thisTop) {
$(elements).height(max_height);
max_height = $el2.height();
elements = [];
}
max_height = Math.max(max_height, $el2.height());
prevTop = thisTop;
elements.push(this);
});
$(elements).height(max_height);
};
It works with the same syntax
$('.equalheight').resEqHeight();
$('.equalheight-frame').resEqHeight({child:'.frame'});