How to get height of the highest children element in javascript/jQuery?

后端 未结 4 628
無奈伤痛
無奈伤痛 2020-12-05 05:10

I need a function to get the height of the highest element inside a div.

I have an element with many others inside (dynamically generated), and when I ask for the he

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 05:33

    I found this snippet which seems more straight forward and shorter at http://css-tricks.com/snippets/jquery/equalize-heights-of-divs

    var maxHeight = 0;
    
    $(yourelemselector).each(function(){
       var thisH = $(this).height();
       if (thisH > maxHeight) { maxHeight = thisH; }
    });
    
    $(yourelemselector).height(maxHeight);
    

提交回复
热议问题