how to retrieve DIV position???

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

    #1

    how to retrieve DIV position???

    Hi, I was wondering how to retrieve the cordinates of a CSS layer with
    javascript.

    I set the layer cordinates as like this in the header:

    <style type="text/css">
    ..classID {
    position: absolute;
    left: 2px;
    top: 100px;
    }
    </style>

    then in the body I have:

    <div id="layerID" class="classID" >
    some html and text
    </div>

    The layer positions properly so I know that works.

    and then in a javascript function I try to retrieve the cordinates by:

    toppos = document.getEle mentById("layer ID").style.to p;
    leftpos = document.getEle mentById("layer ID").style.left ;

    but leftpos and toppos always come back blank.


    Thanks in advance!
    Billy


  • Bas Cost Budde

    #2
    Re: how to retrieve DIV position???

    Billy wrote:
    [color=blue]
    > Hi, I was wondering how to retrieve the cordinates of a CSS layer with
    > javascript.[/color]

    Is getComputedStyl e something for you? Sample article:



    --
    Bas Cost Budde


    Comment

    • Billy

      #3
      Re: how to retrieve DIV position???

      Thanks!

      "Bas Cost Budde" <bas@heuveltop. org> wrote in message
      news:bvrtcq$2vn $10@news2.solco n.nl...[color=blue]
      > Is getComputedStyl e something for you? Sample article:
      >
      > http://www.csie.ntu.edu.tw/~b7506051...examples7.html
      >[/color]


      Comment

      • DU

        #4
        Re: how to retrieve DIV position???

        Billy wrote:
        [color=blue]
        > Hi, I was wondering how to retrieve the cordinates of a CSS layer with
        > javascript.
        >
        > I set the layer cordinates as like this in the header:
        >
        > <style type="text/css">
        > .classID {
        > position: absolute;
        > left: 2px;
        > top: 100px;
        > }
        > </style>
        >
        > then in the body I have:
        >
        > <div id="layerID" class="classID" >
        > some html and text
        > </div>
        >
        > The layer positions properly so I know that works.
        >
        > and then in a javascript function I try to retrieve the cordinates by:
        >
        > toppos = document.getEle mentById("layer ID").style.to p;
        > leftpos = document.getEle mentById("layer ID").style.left ;
        >
        > but leftpos and toppos always come back blank.
        >[/color]

        It should not... unless layerID has moved, was dynamically moved: you do
        not say that in your post description.
        [color=blue]
        >
        > Thanks in advance!
        > Billy
        >
        >[/color]

        var toppos, leftpos;

        toppos = parseInt(docume nt.getElementBy Id("layerID").s tyle.top, 10);
        leftpos = parseInt(docume nt.getElementBy Id("layerID").s tyle.left, 10);

        DU

        Comment

        • DU

          #5
          Re: how to retrieve DIV position???

          Bas Cost Budde wrote:
          [color=blue]
          > Billy wrote:
          >[color=green]
          >> Hi, I was wondering how to retrieve the cordinates of a CSS layer with
          >> javascript.[/color]
          >
          >
          > Is getComputedStyl e something for you? Sample article:
          >
          > http://www.csie.ntu.edu.tw/~b7506051...examples7.html
          >[/color]

          But this will only work in DOM 2 Views and DOM 2 CSS compliant browsers.
          MSIE 6 for windows does not support DOM 2 Views and has limited support
          for DOM 2 CSS.

          DU

          Comment

          Working...