I want to get the x,y co-ordinates of a specific element in my HTML document.
The document contains the code:
var obj = document.getElementById("content");
var x = obj.offsetLeft;
var y = obj.offsetTop;
alert(x + ", " + y);
Then I get the correct answer. However, if I move this code to an external .js file which is then included in the actual HTML file by:
Then it fails with an 'Error object required' message.
What am I doing wrong? I am thinking that maybe the 'document' reference isn't working as it is within a separate physical file, but I wouldn't know how to correct it. Any clues?