PDA

View Full Version : Help. Get String width and height.



NCS_One
06-11-2005, 02:42 AM
Hi

I m trying to make align and valign but for that i need
the string width and height.
I have look for it in books, forums, scripts and nothing,
can some one help me ???

Thanks for all the help you can give.

jscheuer1
06-11-2005, 05:08 AM
You will need to be more specific. Strings do not have width or height. If you want to get the width or height of an element, you can but, it depends upon wether these are already defined or not and if defined, how they are defined, as to what method you use. In all cases the element must have been parsed by the browser before you query its dimensions. Here are some examples:

var element=document.getElementById('myID')

//For elements with attribute width & height defined:

alert(element.width);
alert(element.height);

//For elements with style width & height defined:

alert(element.style.width);
alert(element.style.height);

//For elements with no defined width or height

alert(element.offsetWidth);
alert(element.offsetHeight);

NCS_One
06-11-2005, 12:27 PM
Hi

Thanks for the help.

<td> as the "align" and "valign" how do i do that in a <span>
or <div> ???

Span.height = 100
String(Text).height = 20

to align i do

(Span.height - String(Text).height) / 2 = 40

this is like the valign, but for this i need the String height.

ReMaX
10-26-2007, 03:34 PM
I had the same question!
"element.offsetheight" doesn't work if height is set on "auto".
Need help, please!!!!

greetings
Max

jscheuer1
10-26-2007, 04:58 PM
I had the same question!
"element.offsetheight" doesn't work if height is set on "auto".
Need help, please!!!!

greetings
Max

element.offsetheight won't work for anything. It's (praise to the all mighty camelBackNotation :) ):


element.offsetHeight

That should get you a number that represents the current layout height of the element in pixels, regardless of how it is styled.

ReMaX
10-26-2007, 05:44 PM
Danke, man! Your my god!
I didn' know that upper and lower case is important in JS! I started learning it the day I logged in here the first time.