I have need to be able to determine the width of a given displayed string in order to format other elements on the screen correctly.
My thought was that I could make a hidden div, dump the string to the div, then retrieve the width, something like this:
The problem is that on both IE and Mozilla (I haven't tested others), it returns nothing for the width. This appears to be the case as long as the width was not initially specified.
Is there any way to query the width of the element if it is dynamically sized?
Thanks in advance.
-------------------------------------------------------------------------
Charlie Silverman
Sr. Systems Administrator
Globalstar, LLC
-------------------------------------------------------------------------
We now return you to your regularly scheduled reality.
My thought was that I could make a hidden div, dump the string to the div, then retrieve the width, something like this:
Code:
<script language='javascript'>
getWidth( object ) {
alert("The object's width is " + object.style.width);
}
</script>
<div id='test' style='position:absolute; top:0; left:0; visibility:hidden'>This is a text string</div>
<button value="test" onclick="getWidth(document.getElementById('test'));">
The problem is that on both IE and Mozilla (I haven't tested others), it returns nothing for the width. This appears to be the case as long as the width was not initially specified.
Is there any way to query the width of the element if it is dynamically sized?
Thanks in advance.
-------------------------------------------------------------------------
Charlie Silverman
Sr. Systems Administrator
Globalstar, LLC
-------------------------------------------------------------------------
We now return you to your regularly scheduled reality.