Get coordinates of the mouse pointer, relative to the screen, when the mouse button is clicked on an element:
<!DOCTYPE html> <html> <body> <h2 onclick="showCoords(event)">Click this heading to get the x and y coordinates of the mouse pointer, relative to the screen, when it is clicked.</h2> <p id="demo"></p> <script> function showCoords(event) {//ww w .j av a 2 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>
The screenY property returns the vertical coordinate to the users computer screen of the mouse pointer when an event was triggered.
This property is read-only.
The screenY property returns a Number representing the vertical coordinate of the mouse pointer in pixels.