Output the coordinates of the mouse pointer 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 when it was clicked.</h2> <p id="demo"></p> <script> function showCoords(event) {/* w w w . j ava 2s . c o m*/ var x = event.clientX; var y = event.clientY; var coords = "X coords: " + x + ", Y coords: " + y; document.getElementById("demo").innerHTML = coords; } </script> </body> </html>
The clientY property returns the vertical coordinate to the client area of the mouse pointer when a mouse event was triggered.
The client area is the current window.
This property is read-only.
The clientY property returns a Number representing the vertical coordinate of the mouse pointer in pixels.