Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Help needed

Does anyone know if it is possible to find an HTML element’s exact position on the page (in terms of pixels-from-the-top and pixels-from-the-left) using javascript? The element I have in mind is an image that has not had any positioning applied to it, but I imagine any solution will work for other elements as well. I need something that works in Mozilla/Phoenix, although a solution for IE would be nice as well. It’s for a bookmarklet I’m thinking of writing.

This is Help needed by Simon Willison, posted on 7th February 2003.

View blog reactions

Next: Image Drag bookmarklet

Previous: Real girls eat beef

5 comments

  1. Use the offsetLeft and offsetTop properties, although there are certain caveats; someone (might have been ppk) wrote an Evolt article on this.

    sil - 7th February 2003 17:41 - #

  2. http://www.doxdesk.com/personal/posts/evolt/200204 22-pos.html is some further documentation, including the caveats about nested offsetParents which I always have to work out from first principles. :)

    Stuart Langridge - 7th February 2003 20:14 - #

  3. Here is what ppk has written over the subject: http://www.xs4all.nl/~ppk/js/index.html?/~ppk/js/f indpos.html

    Martijn - 7th February 2003 20:42 - #

  4. Sweet - thanks for the links. I'll have a play and see what happens :)

    Simon Willison - 7th February 2003 20:47 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/02/07/helpNeeded

A django site