This class is again a cross browser supported and is an interesting utility function:

function demo(obj)
{
var posX=0;
var posY=0;
if(typeof(obj.offsetParent) != “undefined”)
{
for(var x=0, y=0;obj; obj=obj.offsetParent)
{
x += obj.offsetLeft;
y += obj.offsetTop;
}
posX=x;
posY=y;
}
else
{
posX=obj.offsetLeft;
posY=obj.offsetTop;
}
alert(“X: “+posX+” Y: “+posY);
}

This function can be called from any HTML code like:

onclick=”demo(this)”


Leave a Reply

Your email address will not be published. Required fields are marked *