Calculating DIV Position in JavaScript
by Rekha[ Edit ] 2009-11-07 15:23:40
The following code is used to calculate the top and left position for the div using javascript.
function getPosition(obj){
var topValue= 0,leftValue= 0;
while(obj){
leftValue+= obj.offsetLeft;
topValue+= obj.offsetTop;
obj= obj.offsetParent;
}
finalvalue = leftValue + "," + topValue;
return finalvalue;
}
You can use the getElementById to pass the element object.
var d = document.getElementById('divname');
getPosition(d);