Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript
:
"Evertjan." <ex**************@interxnl.net> schrieb im Newsbeitrag
news:Xn********************@194.109.133.29... Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript:
> I use dynamic menus and would like to know how I can figure out the
> height of a text (for exalple "Product"). I need it to calculate
> text positions.
<div id=Product
style="width:1px;height:1px;padding:0;font-size:21pt;"
onclick="alert(this.clientHeight+' px height')">
Product</div>
Do you have a function that for example gets a string as an input
parameter and calculates the height of the string with a specific
font?
[please do not underquote on usenet]
<div id=Test
style="position:absolute;visibility:hidden;height: 1px;">x
</div>
<SCRIPT>
function TextHeight(text,points,family){
test=document.getElementById("Test")
test.style.fontFamily=family
test.style.fontSize=points
test.innerHTML=text
return test.clientHeight+' px height'
}
alert("Arial: "+TextHeight("Product","41pt","Arial"))
alert("Verdana: "+TextHeight("Product","41pt","Verdana"))
</SCRIPT>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)