|
|
Calculating DIV Position in JavaScript - Javascript
|
Views : 549
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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 |
|
|
|