O'Reilly logo

JavaScript: The Definitive Guide, 6th Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mouse Events

There are quite a few mouse-related events. Table 17-1 lists them all. All mouse events except “mouseenter” and “mouseleave” bubble. Click events on links and Submit buttons have default actions that can be prevented. You may be able to cancel a context menu event to prevent the display of a context menu, but some browsers have configuration options that make context menus noncancelable.

Table 17-1. Mouse events

TypeDescription
click

A higher-level event fired when the user presses and releases a mouse button or otherwise “activates” an element.

contextmenu

A cancelable event fired when a contextmenu is about to be popped up. Current browsers display context menus on right mouse clicks, so this event can also be used like the click event.

dblclickFired when the user double-clicks the mouse
mousedownFired when the user presses a mouse button
mouseupFired when the user releases a mouse button
mousemove

Fired when the user moves the mouse.

mouseover

Fired when the mouse enters an element. relatedTarget (or fromElement in IE); specifies what element the mouse is coming from.

mouseout

Fired when the mouse leaves an element. relatedTarget (or toElement in IE); specifies what element the mouse is going to.

mouseenter

Like “mouseover”, but does not bubble. Introduced by IE and standardized in HTML5 but not yet widely implemented.

mouseleave

Like “mouseout”, but does not bubble. Introduced by IE and standardized in HTML5 but not yet widely implemented.

The object passed to mouse event handlers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required