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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 Jan, 2019
Like Article
Save Article