How to listen to hover event in JavaScript

DOM
By Jad Joubran · 
Last updated Feb 26, 2024
<div id="box"></div>
const element = document.querySelector("#box");

element.addEventListener("mouseover", event => {
  console.log("Mouse in (over)");
});

element.addEventListener("mouseout", event => {
  console.log("Mouse out");
});