Calculating DIV Position in JavaScript - Javascript Views : 549
Tagged in : Javascript
0 0
Send mail
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);
By Rekha, On - 2009-11-07



    Login to add Comments .