Languages
[Edit]
EN

JavaScript - get mouse position

0 points
Created by:
Palpys
764

In this article, we would like to show you how to get mouse X and Y positions using JavaScript.

Quick solution:

Note:

The coordinates are measured from the upper left corner (0,0).

 

Practical example

Edit

In this example, we use event.clientX and event.clientY properties to get mouse position.

References

Edit
  1. MouseEvent.clientX - Web APIs | MDN
  2. MouseEvent.clientY - Web APIs | MDN

Alternative titles

  1. JavaScript - get mouse X and Y position
  2. JavaScript - get mouse coordinates
  3. JavaScript - get mouse location
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join