Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i get the position of an image (top) on a web page?

Status
Not open for further replies.

mikemackay

Programmer
Oct 22, 2001
4
GB
please would anyone help with this; i need to get the 'top' position of an image and then put it in the window status bar. code is for internet explorer. any help much appreciated.
 
Retrieve it like this:

var imgLeft=document.all.imageName.style.left;
var imgTop=document.all.imageName.style.top;

that's asuming they're positioned absolutely.
Hope this helps,
Spiny
 
Or if not, the following will get the position of any object anywhere on the page, nested in any number of other objects.

This is taken straight from the DHTML menu I posted earlier.

var cNode = document.getElementById('...');
var l = 0;
var t = 0;
while(cNode.tagName!='BODY'){
l+=cNode.offsetLeft;
t+=cNode.offsetTop;
cNode=cNode.offsetParent;
}
}

----------
I'm willing to trade custom scripts for... [see profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top