about getting the size of an element

R

Ricardo Garcia

hi, i was wondering how to get the size of a text element in pixels.

another question:
why in mozilla this doesn´t work (it does in Opera 7 and IE6)
element.style.left = 50;
and how can i solve the problem


Thanks
 
M

Michael Winter

hi, i was wondering how to get the size of a text element in pixels.

What's a text element?
another question:
why in mozilla this doesn´t work (it does in Opera 7 and IE6)
element.style.left = 50;
and how can i solve the problem

Probably because it's invalid. Any length value, other than zero (0),
requires a unit. Change it to

element.style.left = '50px';

Mike
 
M

Martin Honnen

Ricardo said:
i was wondering how to get the size of a text element in pixels.

Get a reference to the element (e.g.
var element = document.getElementById('elementId');
) and then read
element.offsetWidth
element.offsetHeight

why in mozilla this doesn´t work (it does in Opera 7 and IE6)
element.style.left = 50;

Make sure element is a reference to an element object and then make sure
you use syntactically correct CSS e.g.
element.style.left = '50px';
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top