get mouse position with respect to parent element

Posted by ZX12R on Stack Overflow See other posts from Stack Overflow or by ZX12R
Published on 2010-03-25T12:26:26Z Indexed on 2010/03/25 12:33 UTC
Read the original article Hit count: 366

Filed under:
|

this is my setup

<div id="uxcParent">
 <div id="uxcClickable"></div>
</div>

now when a user clicks in the inner element i want the mouse position with respect to the parent div and not the page.

this what i tried.

 var x= e.pageX- obj.offsetLeft;
 var x= e.pageY- obj.offsetTop;

this works fine only when i don't scroll the page. I want the function to return the same values no matter where my elements are on the same page.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript