O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required