mouseover
, mouseout
and mouseenter
, mouseleave
events provide quite similar functionalities, but they work in different scenarios.
mouseover
event is fired when the pointer is moved onto the element which has the listener attached or onto one of its descendants. Since when moving onto the child element, a mouseover
event is fired from the child element and bubbles up to the parent element.
mouseout
event is fired when the pointer is moved off the element which has the listener attached or off one of its descendants. Notice when the pointer is moved onto a child element, the listener on the parent will also be triggered since the pointer move out of the parent’s visible space. mouseout
event will also bubble up.
mouseenter
is fired only when the pointer is moved onto the element that has the listener attached. Different from mouseover
, mouseenter
doesn’t bubble up and it will not be triggered when the pointer is moved onto its descendants.
mouseleave
is fired only when the pointer is moved out of the element that has the listener attached and all of its descendants. mouseleave
event also doesn’t bubble up.
Differences between mouseove
, mouseout
and mouseenter
, mouseleave
Combined mouseenter
with mouseleave
, they work in the way like :hover
in CSS.