Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript – Getting Coordinates of mouse
To get the coordinates of mouse using JavaScript, the code is as follows −
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.sample {
font-size: 25px;
font-weight: 500;
}
</style>
</head>
<body>
<h1>Coordinates of mouse</h1>
<p class="sample"></p>
<h3>Hover the mouse over the screen to get its x and y axis position</h3>
<script>
let sampleEle = document.querySelector(".sample");
document.body.addEventListener("mousemove", (event) => {
sampleEle.innerHTML = "X axis: " + event.x + " Y axis: " + event.y;
});
</script>
</body>
</html>
Output
The above code will produce the following output:

Advertisements