I have a question regarding how to get a div height. I'm aware of .height()
and innerHeight()
, but none of them does the job for me in this case. The thing is that in this case I have a div that is overflown width a overflow: scroll and the div has a fixed height.
If I use .height()
or innerHeight()
, both of them gives me the height of the visible area, but if I want the overflown taken in to account, how do I go about?
Use the
.scrollHeight
property of the DOM node:$('#your_div')[0].scrollHeight
For more information about
.scrollHeight
property refer to the docs:Other possibility would be place the html in a non overflow:hidden element placed 'out' of screen, like a position absolute top and left lesse then 5000px, then read this elements height. Its ugly, but work well.
Another simple solution (not very elegant, but not too ugly also) is to place a inner
div / span
then get his height ($(this).find('span).height()
).Here is an example of using this strategy:
(This specific example is using this trick to animate the max-height and avoiding animation delay when collapsing (when using high number for the max-height property).