Originally Posted by timgolding
Hi. Does anyone know a way of computing the size that a box would be? E.g not actually rendering the box on the page but working out it's dimensions before it is rendered. The reason is my bosses are having me have a text swap script that switches some text when you hover over certain object. I need to find out what the maximum size of box would be for the different texts because that text that is rendered from the start is not necessarily the maximum.
Unless someone knows a simpler way, this is what i would try.
Generate a div, styled: width:1px; height:1px; visibility:hidden; overflow:hidden; position:absolute; left:0; top:0
This element should be able to contain anything at its natural dimensions without disturbing the flow of the document.
Append to the div your generated text container and measure its offsetHeight and offsetWidth.
Remove the container from the div and position it or whatever according to its known size.