473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

getElementById problem

JKD
After writting this code...

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

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

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 ?
Jul 23 '05 #1
3 1163
Ivo

"JKD" <JK*@JKDSoft.cjb.net> wrote
After writting this code...

document.write('<div id="foo"
style="position:absolute;top:0;left:0;width:10;hei ght: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.PixelLe ft);

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/a...erties/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
--
Ivo
http://www.vansandick.com/
Jul 23 '05 #2
> alert(document.getElementById('foo').style.PixelLe ft);

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;
Jul 23 '05 #3
Riyaz Mansoor wrote:
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.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary Mayor | last post by:
Hi, I'm back again. Basically i'm trying to draw a box over an image which is turning out to be a nightmare. The problem i'm getting at the moment is that i'm creating a line with <div which works...
8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
7
by: Gerry | last post by:
Hi, I have a javascript function which uses the method document.getElementById. I'm using it to decide whether a checkbox has been ticked or not. This decision is encoded in an if statement...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
10
by: JJA | last post by:
I'm trying to use document.getElementByID inside a function where the ID is passed as an argument. I get the same error ("Element has no properties") on the same statement inside the commonCheck...
1
by: Warren Thai | last post by:
I am writing a webpage to display a small quiz, below is the code of the webpage. I used a for loop so that if there are a lot of questions, it would reduce the code. but the line ----...
24
by: Robi | last post by:
I have the following problem: I populate a page with a specific amount of <div id="MyTest"> containers inside another <div> container. for (i=0; i < MyString.length; i++) document.write('<div...
9
by: jason.hau | last post by:
Ok, interesting problem here, I have a webcontrol that holds a textbox and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0 (this is javascript related, bear with me). The...
4
by: Claudio Calboni | last post by:
Hello folks, I'm having some performance issues with the client-side part of my application. Basically, it renders a huge HTML table (about 20'000 cells in my testing scenario), without content....
3
by: djp1988 | last post by:
I have made up a code allowing users to click on a tab and show content in a neat white box, similar to what yahoo have on their homepage. I have used 5 divs, all but one set to display:none and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.