mouseover bubbles and fires again every time the pointer moves onto the element or any of its descendants. mouseenter does not bubble and fires once when the pointer enters the element's box, ignoring movement between its children. The same pairing exists for mouseout/mouseleave. For hover logic on a single element you almost always want mouseenter/mouseleave (or pointerenter/pointerleave).
<div id="card">
<h3>Title</h3>
<p>Body text</p>
</div>
let over = 0, enter = 0;
card.addEventListener('mouseover', () => console.log('over', ++over));
card.addEventListener('mouseenter', () => console.log('enter', ++enter));
Move the pointer into #card, then across the <h3> and <p>:
mouseenter logs once.mouseover logs on entering the card, again on entering <h3> (fired on <h3>, bubbles to the card), again when moving to <p>, and even when moving from a child back onto the card's own padding.mouseover / mouseout | mouseenter / mouseleave | |
|---|---|---|
| Bubbles | Yes | No |
| Fires when moving between children | Yes | No |
e.target | The innermost element entered | Always the element the listener is on |
| Works with event delegation | Yes | Not directly (use capture or mouseover) |
relatedTarget | Element the pointer came from / goes to | Same |
mouseenter/mouseleave: tooltips, hover cards and highlight effects bound to a specific element. You get exactly one enter and one leave, so there is no flicker and no need for guards.mouseover/mouseout: delegation. One listener on a table or list can track which row is hovered via e.target.closest('tr'). To emulate enter/leave semantics here, ignore events whose relatedTarget is still inside the same row:table.addEventListener('mouseover', (e) => {
const row = e.target.closest('tr');
if (!row || row.contains(e.relatedTarget)) return; // moved within the row
highlight(row);
});
pointerenter, pointerover, …). They have the same bubbling difference but unify mouse, pen and touch, and are what you should build hover/press interactions on today.mouseenter) are inaccessible on touch and to keyboard users. Always pair them with click/focus handling, and in CSS consider @media (hover: hover).:hover, not JS.relatedTarget is the tool for filtering inner moves with mouseover.Spotted a mistake or a rights concern? Report an issue