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 height of the container element using $(elem).height(), I get a smaller height than some of the contents inside it. Some of the elements inside are images that are bigger than the size this element says to have.
I need to know the highest element so I can get it's height.
innerHeight() - Returns the height of an element (includes padding) outerWidth() - Returns the width of an element (includes padding and border) outerHeight() - Returns the height of an element (includes padding and border)
Answer: Use the JavaScript height() method You can set the height of a <div> box dynamically using the jQuery height() method.
In jQuery, height method is used to get the height of any element in HTML. The height method sets and returns the height of the HTML elements.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With