O'Reilly logo

The Book of JavaScript, 2nd Edition by thau!

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

Fancy Event Handling

Dynamic web pages call for dynamic reactions to user actions. We've discussed how to write JavaScript that reacts when users click links, buttons, and form elements. Now it's time to learn about more complicated event handling: how to accurately read the keyboard and the mouse.

The event Object

Whenever an event occurs, an event object is generated. The nature of this object depends on the event which generated it. To access the event object, simply pass the keyword event to whichever function is handling the event:

<a href = "#" onClick = "handleClick(event); return false; ">Click me!</a>.

The event object is most frequently accessed when you want to know which key a user has pressed, or precisely where the mouse is.

Keyboard ...

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