[Javascript] X and Y co-ordinates of an object

Emmanuel emmanuel at quomodo.com
Mon Feb 26 10:26:27 CST 2007


At 3:58 PM +0000 2/26/07, Alan Easton wrote:
>function getbasket() {
>  var x=document.getElementById("basket").x;
>  var y=document.getElementById("basket").y;
>  alert("x: "+ x +" y: "+ y +"");
>}

I would try:

function getbasket() {
  var x=document.getElementById("basket").offsetLeft;
  var y=document.getElementById("basket").offsetTop;
  alert("x: "+ x +" y: "+ y +"");
}

However, expect those to return undefined if the div is invisible 
(style.display set to "none").

Emmanuel



More information about the Javascript mailing list