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.
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, either by their IDs or actual references to DOM elements
2. The type of event to listen for
3. A reference to the callback function to execute on detection of the event
4. (Optional) an arbitrary object to pass as an argument to the callback
5. (Optional...