Automatic adjust element height based on the tallest element

Last Updated: January 28, 2019

It will loop all elements based on class and adjust the height based on the tallest element.

HTML Code

jQuery Code

$(window).resize(function(){
    initArticleBox(".box");
});
    
$(window).load(function(){
    initArticleBox(".box");
});
function initArticleBox(selector){
    var box = $(selector)
    box.height("auto");

    if ($(window).width() > 768){
        var maxHeight = 0;
        var article = box.each(function(){

            maxHeight = Math.max(maxHeight, jQuery(this).height());

        }).height(maxHeight);;

    }else{
        box.height("auto");
    }
}

Add your feedback or comment below: