What is the role of clientX Mouse Event in JavaScript?

HTMLJavascriptProgramming Scripts

When a mouse event is triggered, the clientX mouse event property is used to get the horizontal coordinate of the mouse pointer. This is according to current window.

Example

You can try to run the following code to learn how to implement clientX Mouse event in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <p onclick = "coordsFunc(event)">
         Click here to get the x (horizontal) and y (vertical) coordinates
         (according to current window) of the mouse pointer.
      </p>
      <script>
         function coordsFunc(event) {
            var x_coord = event.clientX;
            var y_coord = event.clientY;
            var xycoords = "X coords= " + x_coord + ", Y coords= " + y_coord;
            document.write(xycoords);
         }
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 16:19:53
Advertisements