Position of element

Hi,

I’m trying to find the position of an element with respect to the view port area. So, when the user scrolls the page down, I want to know the x and y positions of the element with respect to the viewing (view port) area. Can anyone help with this?

The overall goal is to know exactly where on the element this user clicked.

Do you need the xy coords relative to the top left hand corner of the clicked element or the viewport?

The X&Y coordinates relevant to the element clicked

When the user clicks an element you can pass the click event to a function.

The event object’s offsetX and offsetY properties will then contain the x and y coords of where the mouse was clicked relative to the element that was clicked.

Hey,

Sorry I didn’t respond sooner. I got caught up in other things. The offsetX & Y don’t seem to be properties accessible at least in FireFox. I didn’t bother testing beyond that. Aside from that, I found the solution. You can use the “document.documentElement.scrollTop” to detect the current position of the scrollbar. Since I know the location of the viewing port, I can subtract that from the offset location of the element.

Thanks for your help. I appreciate it.