Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js
Registering Event Handlers
Functions that handle events are called event handlers.
Assigning an event handler to an event on a DOM node is
called registering an event handler. Previously, we have
registered event handlers using the inline model, treating
events as attributes of XHTML elements (e.g.,
ONCLICK="myfunction()">). Another model, known as
the traditional model, for registering event handlers is
demonstrated alongside the inline model in Fig. 11.1.
In the earliest event-capable browsers, the inline model was the only way to handle events. Later, Netscape developed the traditional model and Internet Explorer adopted it. Since then, both Netscape and Microsoft have developed separate (incompatible) advanced event models with more functionality than either the inline or the traditional model. Netscapes advanced model was adapted by the W3C to create a DOM Events Specification. Most browsers support the W3C model, but Internet Explorer 7 does not. This means that to create cross-browser websites, we are mostly limited to the traditional and inline event models. While the advanced models provide more convenience and functionality, most of the features can be implemented with the traditional model.
Line 35 assigns "
handleEvent()" to the onclick attribute of the
div in lines 3536. This is the inline model for event registration weve seen in previous examples. The div in line 39 is assigned an event handler using the traditional model. When the body element (lines 3340) loads, the
registerHandler function is called.
handleEvent as the event handler for the onclick event of the
div with the id "traditional". Line 27 gets the
div, and line 28 assigns the function
handleEvent to the
divs onclick property.