How to find the coordinates of the cursor with JavaScript?

HTMLJavascriptProgramming Scripts

To find the coordinates of the cursor in JavaScript, use event.clientX and event.clientY. You can try to run the following code to get cursor coordinates in JavaScript:

Example

<!DOCTYPE html>
<html>
   <head>
      <script>
         function coordinatesFunc(event) {
            document.write("Coordinate(X) = " + event.clientX + "<br>Coordinate(Y) = " + event.clientY);
         }
      </script>
   </head>

   <body>
      <div onmousedown="coordinatesFunc(event)">Click me to get coordinates of cursor</p>
   </body>
</html>
raja
Published on 26-Feb-2018 13:06:20
Advertisements