Javascript examples for DOM:Mouse Event
The screenX property returns the horizontal coordinate of the mouse pointer.
This property is read-only.
A Number, representing the horizontal coordinate of the mouse pointer, in pixels
The following code shows how to get coordinates of the mouse pointer, relative to the screen.
<!DOCTYPE html> <html> <body> <h2 onclick="showCoords(event)">Click this heading.</h2> <p id="demo"></p> <script> function showCoords(event) {// ww w . j a va2 s . c o m var x = event.screenX; var y = event.screenY; var coords = "X coords: " + x + ", Y coords: " + y document.getElementById("demo").innerHTML = coords; } </script> </body> </html>