Yes, I have just tried that. Since I am trying to find the position of the element as it is displayed globally (based on body element) on the page, that method does not work. It will give me the position as based upon its parent, without taking into account scrolling or any parent elements.
Yes, I have just tried that. Since I am trying to find the position of the element as it is displayed globally (based on body element) on the page, that method does not work. It will give me the position as based upon its parent, without taking into account scrolling or any parent elements.
use that on the parent element too. I guess I must not understand your problem
Since I am trying to find the position of the element as it is displayed globally (based on body element) on the page,
If by that you mean its current displacement from the top of the body element, does it make sense to subtract the scrollTop/Left of the body element? This isn't tested but may be worth a try:
Code:
function ElemAbsPos(obj){
var x=0;
var y=0;
while(obj){
y += obj.offsetTop;
y -= obj.offsetParent ? obj.scrollTop : 0;
x += obj.offsetLeft;
x -= obj.offsetParent ? obj.scrollLeft : 0;
obj=obj.offsetParent;
}
return [x,y];
}