offsetLeft & Top differ for different element types?

Discussion in 'Javascript' started by Pieter Van Waeyenberge, Feb 15, 2004.

  1. Hello

    In the code below, theres a DIV, a TABLE and another DIV , each with an
    image in it.

    When i read out the offsetLeft/Top from imgB in the table , i get offset
    values relative to the containng TD ... *as it should be*, HOWEVER, the
    offsetLeftTop values for imgA/C in the DIVs are calulated realtive to the
    window border ???? is this normal

    this happens on both NS7 & IE6

    sample code (you can copy/paste ... i tested this):

    <html>
    <head>
    <script language="JavaScript">
    onload = function(){
    var imgA = document.getElementById('imgA');
    var imgB = document.getElementById('imgB');
    var imgC = document.getElementById('imgC');

    alert(imgA.offsetLeft)
    alert(imgA.offsetTop)

    alert(imgB.offsetLeft)
    alert(imgB.offsetTop)

    alert(imgC.offsetLeft)
    alert(imgC.offsetTop)

    }

    </script>
    </head>

    <body>

    <div>
    <img src="0.jpg" id="imgA" width="100" height="100">
    </div>

    <table>
    <tr>
    <td>
    <img src="1.jpg" id="imgB" width="100" height="100">
    </td>
    </tr>
    </table>

    <div>
    <img src="2.jpg" id="imgC" width="100" height="100">
    </div>


    </body>
    </html>
     
    Pieter Van Waeyenberge, Feb 15, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rahul
    Replies:
    16
    Views:
    504
    dohboy
    Feb 26, 2008
  2. Csaba Hoch
    Replies:
    1
    Views:
    278
    andrew cooke
    Jan 31, 2009
  3. Pieter Van Waeyenberge
    Replies:
    2
    Views:
    148
    Pieter Van Waeyenberge
    Feb 16, 2004
  4. Keith Thornhill

    offsetLeft/Top Bug in Firefox? (value is 8)

    Keith Thornhill, Aug 15, 2004, in forum: Javascript
    Replies:
    4
    Views:
    275
    Grant Wagner
    Aug 16, 2004
  5. moha297
    Replies:
    31
    Views:
    353
    GTalbot
    Feb 9, 2010
Loading...

Share This Page