JavaScript clientX and clientY Coordinates

event.clientX and event.clientY give the horizontal and vertical position of a mouse event relative to the browser viewport. The top-left corner of the viewport is 0, 0.

element.addEventListener('click', (event) => {
  console.log(event.clientX, event.clientY);
});

DEMO of X & Y coordinates of mouse click

Table of Contents

What clientX and clientY Measure Top ↑

clientX measures from the left edge of the viewport and clientY from the top edge. Scrolling the document does not turn these values into document coordinates; for document-relative positions, compare with pageX/pageY or add the page scroll offsets.

Complete Working Source Top ↑

<div id="d1" aria-live="polite"></div>
<div id="my_page2">**</div>
<script>
const output = document.getElementById('d1');
document.addEventListener('click', (event) => {
  output.textContent = `X: ${event.clientX}  Y: ${event.clientY}`;
});
</script>

Using coordinate and key-event ideas together, see the Virtual Keyboard tutorial.

screenX/screenY are relative to the screen, while offsetX/offsetY describe the position relative to the event target's padding edge. Choose the coordinate system that matches the task.

Event Handling onMouseOver and onMouseOut




Subscribe to our YouTube Channel here



plus2net.com







25-01-2021

Would you please post this code using PHP,
Thank you.



We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer