How can I get the mouse coordinates relative to a parent div? Javascript
问题 I currently have a div structured with other elements inside of it. Something similar to below; <div id="container" style="position: relative; width: 500px; height: 500px;"> <div style="position: absolute; left: 50px; top: 50px;"></div> <div style="position: absolute; left: 100px; top: 100px;"></div> </div> I am trying to get the mouse position relative to the div with the id container . So far I have this; function onMousemove(event) { x = event.offsetX; y = event.offsetY; }; var elem =