-
Recent Posts
Tags
app engines attributes cgi database DBI Debian frameworks full screen terminal GWT hacks hardware hobbit howto html inheritance javascript jQuery libraries Linux mac oracle OSX parallels Perl photoshop pixels PostgreSQL programming qa regression testing screen size Software Development style template toolkit term Theory translation type cast User Interface virtual machine virtual machines visual studio vmware web design web programming
mouseover/mouseout v.s. mousenter/mouseleave events in JavaScript and JQuery
The typical event example, and the one used by this lynda.com JQuery tutorial, is the yellow div that highlights red when you roll your mouse over it.
When I initially wrote a second example (see below) where the div being highlighted contains an inner div, I experienced some odd behavior. The div would highlight, but then de-highlight when the mouse moved over the child div. You can see in the code below, that I was mixing mouseover (normally paired with mouseout) and mouseleave (normally paired with mouseenter).
A blog post by Kurniawan explained this behavior:
“Mouseover fires when the pointer moves into or out from child element, while mouseenter does’t.”
Here is perhaps a clearer example: Instead of toggling highlighting, the events are printing to the screen. You see that the events fire when the mouse enters and leaves the child div, even though we have only bound the events to the parent: