This little function should do the trick (credit to jumper on
http://eksperten.dk):
function getPos(elm) {
for(var
zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
return {x:zx,y:zy}
}
To use the function you should use an object (an image, div etc.) as the
argument. The function returns another object with the x and y coordinates:
elm = document.getElementById("divElement");
pos = getPos(elm);
alert(pos.x); // this is the x-coordinate
alert(pos.y); // ..and the y-coordinate
// You can also do something like this:
coordinateX = getPos(elm).x;
// or
coordinateY = getPos(document.getElementById("divElement")).y;