O'Reilly logo

YUI 2.8 Learning the Library by Dan Wellman, Daniel Barreiro

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

A look at the Event Utility

There are five classes defined within the Event Utility. The first, YAHOO.util.Event provides the mechanism to interact with the events built into the browser, which is supplemented by YAHOO.util.KeyListener, which deals solely with listening for keyboard events.

The other classes provide means for your own applications to declare, fire, and listen to events in a similar way to how the browser does. We'll see this later.

Listeners

The .addListener() (alias .on()) method is the one we'll use most often, as this is the method that adds the listener, which executes the callback function whenever the event in question occurs. It takes up to five arguments:

  1. The HTML element or array of elements to bind the event listener to, ...

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