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

后端 未结 4 630
無奈伤痛
無奈伤痛 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:37

    If the div element is smaller than it's children, the children are probably floating. Can you allow the div to be as large as children?

    If you can, add a clearing element at the bottom to make the div wrap it's children:

    test

    test1 test2

    Or apply a clearfix CSS solution to do pretty much the same thing but without extra markup or a clearing div.

    The containing div will then get the same height as the highest child element, and you can get it by:

    $("#someParent").height();
    

提交回复
热议问题