faqts : Computers : Programming : Languages : JavaScript : Links

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 8 people (63%) answered Yes
Recently 5 of 8 people (63%) answered Yes


Ho can I determine the x,y position of a link - not through catching the mouse position

Jun 12th, 2002 07:29
David Blackledge, Nikolai Onken,

In Netscape 4, each link has an x and y property that are the top-left 
corner of the link (or the top-left corner of the last line of the link 
if it wraps around to another line... that's a bug)
var myx = document.links[0].x;
var myy = document.links[0].y;
Note, if you specify a "name" attribute, it becomes an anchor, and you 
have to get the x and y from the anchors array's Anchor object.
in IE, you can get the position of any element with a little bit of 
var obj = document.links[0];
var myx = 0;
var myy = 0;
while(obj != document.body) {
 myx += obj.offsetLeft;
 myy += obj.offsetTop;
 obj = obj.offsetParent;
That loop could be off slightly (maybe you need to add the 
document.body's offsetLeft and Top as well)... I'm doing this from 
I'm not sure what you'd do in the W3C DOM standard, though.