getElementById problem

J

JKD

After writting this code...

document.write('<div id="foo"
style="position:absolute;top:0;left:0;width:10;height:10;background:#fffff0;font-size:1"></div>');

.... I've tryed to see its properties with the next line:
alert(document.getElementById('foo').style.PixelLeft);

but both in firefox and internet explorer return "undefined".

What is the error? How can I access properly to that div in firefox and
iexplore ?
 
I

Ivo

JKD said:
After writting this code...

document.write('<div id="foo"
style="position:absolute;top:0;left:0;width:10;height:10;background:#fffff0;
font-size:1"></div>');

Probably unrelated to the issue below, but to prevent a future problem, make
a habit of specifying units (px, em, cm, % etc.) with *all* numeric values,
so browsers are more likely to agree on the size they think you want.
... I've tryed to see its properties with the next line:
alert(document.getElementById('foo').style.PixelLeft);

but both in firefox and internet explorer return "undefined".

What is PixelLeft then? Another IE only aberration? Indeed, it is clearly
written in the documentation - if you can find it:
<
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/pixelle
ft.asp >
"There is no public standard that applies to this property."

which means it 's not in the W3c specs and not likely to make it there any
time soon either.

If anything, it would begin with a lowercase letter, as both clientLeft and
scrollLeft do, which are the properties we usually deal with.

HTH
 
J

Julian Turner

alert(document.getElementById('foo').style.PixelLeft);

1. The property is case sensitive. It should have a lowercase first
letter: "pixelLeft".

2. "pixelLeft" is only supported by IE.

Alternatives are:-

- "style.left" - which will return the value defined in the
inline style for the DIV.

- "offsetLeft" which returns the actual calculated position of
the element relative to the BODY or any absolutely positioned parent
(given by "offsetParent"). This is a property of the element, not the
style object. Thus: document.getElementById("foo").offsetLeft;
 
R

RobB

Riyaz said:
i haven't tried your suggestion yet as i am not home, but isn't this really
peculiar behavior from IE? or could item be some kind of reserved word?

Not really a reserved word - but it is a common (DOM) method and
should not be used as an identifier, to avoid clashes.
 

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
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top