I have always used the mouseover
event, but while reading the jQuery documentation I found mouseenter
. They seem to function exactly the same.
Is there a difference between the two, and if so when should I use them?
(Also applies for mouseout
vs mouseleave
).
You can try out the following example from the jQuery doc page. It's a nice little, interactive demo that makes it very clear and you can actually see for yourself.
In short, you'll notice that a mouse over event occurs on an element when you are over it - coming from either its child OR parent element, but a mouse enter event only occurs when the mouse moves from outside this element to this element.
Or as the
mouseover()
docs put it:Explains it pretty well here
Only Chrome let you suggest a name to use when clicking a link with dynamically generated content. However, you can generate the content when the mouse cursor is over the link and put it as DATAURI in a standard static href. This enables the "Save link as.." option in right-click menu.
As is often true with questions like these, Quirksmode has the best answer.
I would imagine that, because one of jQuery's goals is to make things browser agnostic, that using either event name will trigger the same behavior.Edit: thanks to other posts, I now see this is not the caseMouseenter and mouseleave do not react to event bubbling, while mouseover and mouseout do.
Here's an article that describes the behavior.