Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 477
Leandro Ardissone Avatar asked Jul 02 '09 19:07

Leandro Ardissone


People also ask

How can get current height of div in jQuery?

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)

How do I set dynamic height in jQuery?

Answer: Use the JavaScript height() method You can set the height of a <div> box dynamically using the jQuery height() method.

Which jQuery method is used to get or set the height of an HTML element?

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.


1 Answers

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); 
like image 171
gebeer Avatar answered Oct 30 '22 13:10

gebeer