Getting the Mouse Coordinates

function myHandler(e){   $("#p1").html("From left side of screen: " + e.screenX);   $("#p2").html("From right side of screen: " + e.screenX);   $("#p3").html("From left side of browser: " + e.clientX);   $("#p4").html("From right side of browser: " + e.clientY); }

For many graphical web apps, it is critical to not only know what target mouse events originated in, but the exact location on the screen or in the web browser display. The JavaScript mouse event object includes the event.screenX and event.screenY attributes that allow you to get the offset from the top and left of the screen in pixels.

Additionally, the JavaScript mouse event includes the event.clientY and event.clientY ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.