Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>Mouse Events</h1>
<h2>The offsetX Property</h2>
<p>The offsetX property returns the x-coordinate the mouse cursor, relative to the target element.</p>
<p>In this example, the red DIV is the target element.</p>
<p>Click inside the red DIV element:</p>
<div onclick="myFunction(event)" style="border:2px solid red;height:100px"></div>
<p id="demo"></p>
<script>
function myFunction(event) {
  let x = event.offsetX;
  document.getElementById("demo").innerHTML = "The x-coordinate is: " + x;
}
</script>
</body>
</html>