Java Script - Retrieving the position of an object



Retrieving the horizontal position of an object using Java Script

//Control ID: "txtName"
var curleft = 0;
var obj = document.getElementById("txtName");
if(obj.offsetParent) {
	while(obj.offsetParent) {
		curleft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
} else if(obj.x)
	curleft += obj.x;

Retrieving the vertical position of an object using Java Script

//Control ID: "txtName"
var curtop = 0;
var obj = document.getElementById("txtName");
if (obj.offsetParent) {
	while (obj.offsetParent) {
		curtop += obj.offsetTop
		obj = obj.offsetParent;
	}
} else if(obj.y)
	curtop += obj.y;

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.