Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Experts,

I have a jquery element with a preset height 200px, overflow hidden and position relative; that cannot be changed. I would like to get the height of the actual element since the items inside it differ in height and quantity. That is, no one element is exactly 200px because if one has 2 items it is very short and if the other has 20 items it would be relatively much taller. One way to do this is to traverse the items in the element and += their height right?

a). Is there an efficient jquery loop to do this? (for each...)
b). Do you know of any other way of getting the REAL height of the element as it appears on screen?

If you do not understand my question, kindly let me know and I will find a better way.

Thanks a lot for your assistance,
Justin
Posted

If you need to know what the height would have been without some of it being hidden, refer to the scrollHeight property (even though there's no scrollbar with overflow hidden):

$('#whatever')[0].scrollHeight
 
Share this answer
 
Use this function to find the max height:

function() {

var max = 0;

this.each(function() {
max = Math.max( max, $(this).height() );
});

return max;
};
 
Share this answer
 
Comments
Brian A Stephens 22-Apr-13 10:39am    
This code returns the height of ONE item (the largest item) within the div, not the cumulative total height. The question is about the total height.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900