[Javascript] Thoughts on building form elements/similar divs

Hakan hakan at backbase.com
Mon Jul 11 03:53:06 CDT 2005


Glenn E. Lanier, II wrote:
> So, how can I get the top and left coordinates of a single item?
> 
> document.getElementById('text1').style.top returns blank for me, even when I
> define a style and explicitly set top to a value.

This is a funny one, let me assure you. If your markup is very basic, 
you can go for element.offsetTop and element.offsetLeft. If your markup 
is not very basic, you can read up on

http://www.quirksmode.org/js/findpos.html

and cry a bit.

If you're only supporting IE and Mozilla, I can dig up some proprietary 
functionality to get the actual top/left coordinate of an element in 
those browsers.

Regards,
H



More information about the Javascript mailing list