getElementById problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JKD

    getElementById problem

    After writting this code...

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

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

    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 ?
  • Ivo

    #2
    Re: getElementById problem


    "JKD" <JKD@JKDSoft.cj b.net> wrote[color=blue]
    > After writting this code...
    >
    > document.write( '<div id="foo"
    >[/color]
    style="position :absolute;top:0 ;left:0;width:1 0;height:10;bac kground:#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.
    [color=blue]
    > ... I've tryed to see its properties with the next line:
    > alert(document. getElementById( 'foo').style.Pi xelLeft);
    >
    > but both in firefox and internet explorer return "undefined" .[/color]

    What is PixelLeft then? Another IE only aberration? Indeed, it is clearly
    written in the documentation - if you can find it:
    <
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

    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



    Comment

    • Julian Turner

      #3
      Re: getElementById problem

      > alert(document. getElementById( 'foo').style.Pi xelLeft);

      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.getEle mentById("foo") .offsetLeft;

      Comment

      • RobB

        #4
        Re: getElementById problem

        Riyaz Mansoor wrote:
        [color=blue]
        > 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?[/color]

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

        Comment

        Working...