<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mouse Event Example</title>
<style>
#colorBox {
width: 200px;
height: 200px;
background-color: lightblue;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="colorBox"></div>
<p id="coordinates"></p>
<script src="script.js"></script>
</body>
</html>
document.addEventListener("DOMContentLoaded", function() {
const colorBox = document.getElementById("colorBox");
const coordinates = document.getElementById("coordinates");
colorBox.addEventListener("mouseover", function() {
colorBox.style.backgroundColor = "lightgreen";
});
colorBox.addEventListener("mouseout", function() {
colorBox.style.backgroundColor = "lightblue";
});
colorBox.addEventListener("mousemove", function(event) {
coordinates.textContent = `Mouse coordinates: (${event.clientX}, ${event.clientY})`;
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.