So after reading a recently answered question i am unclear if i really understand the difference between the mouseenter()
and mouseover()
. The post states
MouseOver():
Will fire upon entering an element and whenever any mouse movements occur within the element.
MouseEnter():
Will fire upon entering an element.
I came up with a fiddle that uses both and they seem to be quite similar. Can someone please explain to me the difference between the two ?
I have also tried reading the JQuery definitions, both say the same thing.
The mouseover event is sent to an element when the mouse pointer enters the element
The mouseenter event is sent to an element when the mouse pointer enters the element.
Can someone please clarify with an example?
This is one of the best examples I have found of:
http://bl.ocks.org/mbostock/5247027
See the example code and demo at the bottom of the jquery documentation page:
http://api.jquery.com/mouseenter/
The mouseenter event differs from mouseover in the way it handles event bubbling. The mouseenter event, only triggers its handler when the mouse enters the element it is bound to, not a descendant. Refer: https://api.jquery.com/mouseenter/
The mouseleave event differs from mouseout in the way it handles event bubbling. The mouseleave event, only triggers its handler when the mouse leaves the element it is bound to, not a descendant. Refer: https://api.jquery.com/mouseleave/
This example demonstrates the difference between the mousemove, mouseenter and mouseover events:
https://jsfiddle.net/z8g613yd/
HTML:
CSS:
JS:
onmousemove
: occurs every time the mouse pointer is moved over the div element.onmouseenter
: only occurs when the mouse pointer enters the div element.onmouseover
: occurs when the mouse pointer enters the div element, and its child elements (p and span).You see the behavior when your target element contains child elements:
http://jsfiddle.net/ZCWvJ/7/
Each time your mouse enters or leaves a child element,
mouseover
is triggered, but notmouseenter
.Though they operate the same way, however, the
mouseenter
event only triggers when the mouse pointer enters the selected element. Themouseover
event is triggered if a mouse pointer enters any child elements as well.