Javascript – using javascript find the height a div is going to take before it is rendered

htmljavascript

I have a div which contains different amount of text at different moments (determined by what the server decides to send). I want to find the height this div would take if rendered. At the point when I want the height, the div is not being rendered (display:none). The display is to be set to 'block' later.

I have tried .offsetHeight and it works well after I set display:block for the div. However, I want the height at the time when display is set to 'none'. Any ideas?

Best Solution

You cannot determine the height until it's rendered. So with display: none;, it won't be possible.

A work around would be to set visibility:hidden; and change it to visible when you are done with your resizing