HTML | DOM MouseEvent clientX Property
The MouseEvent clientX property is a read-only property which is used to return the horizontal coordinate of the mouse pointer based on the current window when a mouse event was triggered.
Syntax:
event.clientX
Return Value: It returns a number which represents the vertical coordinate of the mouse pointer in pixels.
Below program illustrates the MouseEvent clientX property :
Finding out the horizontal coordinates of the mouse pointer when the mouse button is clicked on an element.
<!DOCTYPE html> <html> <head> <title>MouseEvent clientX Property</title> <style> h1 { color: green; } h2 { font-family: Impact; } body { text-align: center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>MouseEvent clientX Property</h2> <p onclick="coord(event)">To get the x of the mouse pointer, click on this paragraph. </p> <p id="gfg"></p> <script> function coord(event) { var getXCoord = event.clientX; var result = "X coordinate: " + getXCoord; document.getElementById("gfg").innerHTML = result; } </script> </body> </html> |
Output:

After clicking on the paragraph:

Supported Web Browsers:
- Opera
- Internet Explorer
- Google Chrome
- Firefox
- Apple Safari
Recommended Posts:
- HTML | DOM MouseEvent pageX Property
- HTML | DOM MouseEvent screenX Property
- HTML | DOM MouseEvent screenY Property
- HTML | DOM MouseEvent offsetX Property
- HTML | DOM MouseEvent clientY Property
- HTML | DOM MouseEvent pageY Property
- HTML | DOM MouseEvent relatedTarget Property
- HTML | DOM MouseEvent offsetY Property
- Javascript | MouseEvent which Property
- JavaScript | MouseEvent Button Property
- JavaScript | MouseEvent shiftKey Property
- Javascript | MouseEvent altKey Property
- Javascript | MouseEvent ctrlKey Property
- HTML | DOM MouseEvent
- Javascript | MouseEvent getModifierState() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



