Binding to events
Using the event callbacks exposed by each component is the standard way of handling interactions. However, in addition to the callbacks listed in the previous table, we can also hook into another set of events fired by each component at different times.
We can use the standard jQuery on()
method to bind an event handler to a custom event, fired by the menu widget in the same way that we could bind to a standard DOM event, such as a click.
The following table lists the menu's custom binding events and their triggers:
Event |
Fired when… |
---|---|
|
The menu is created |
|
A menu item is selected |
|
A menu gains focus or when any menu item is activated |
|
The menu loses focus |
The first event menucreate
is fired, as soon as the menu object is initialized; the next three will be fired depending on whether a menu item has been selected by the user.
Let's see this type of event usage in action; change the final <script>
element in menu8.html...