views:

80

answers:

2

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?

+3  A: 

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

RageZ
The trouble is that display:block + visibility:hidden would still make the browser reserve space for the div making a blank area appear on the screen. This is not wanted.
Crimson
@Crimson: I am afraid there is no solution then. at least not I aware of
RageZ
what you could try is render it offscreen (i.e., out of the viewport), measure it, then either destroy that, then rerender the same thing back in the place you want (or move it to the place you want)?
Chii
+2  A: 

If you position the element absolute and do as RageZ says you can measure it. Then you could set the position back to static.

anddoutoi