jQuery in Action
Understanding the browser event models
97
4.1.3 The Internet Explorer Event Model
Internet Explorer (both
IE6
and, most disappointingly,
IE7
) doesn't provide sup-
port for the
DOM
Level 2 Event Model. Both these versions of Microsoft's browser
provide a proprietary interface that closely resembles the bubble phase of the
standard model.
standard model.
Rather than
addEventListener()
, the Internet Explorer Model defines a
method named
attachEvent()
for each
DOM
element. This method, as follows,
accepts two parameters similar to those of the standard model:
attachEvent(eventName,handler)
The first parameter is a string that names the event type to be attached. The stan-
dard event names aren't used; the name of the corresponding element property
from the
dard event names aren't used; the name of the corresponding element property
from the
DOM
Level 0 Model is used--
onclick
,
onmouseover
,
onkeydown
, and so on.
The second parameter is the function to be established as the handler, and
as in the Basic Model, the
Event
instance must be fetched from the
window
.event
property.
What a mess! Even when using the relatively browser-independent
DOM
Level
0 Model, we're faced with a tangle of browser-dependent choices to make at each
stage of event handling. And when using the more capable
stage of event handling. And when using the more capable
DOM
Level 2 or Internet
Figure 4.5 Clicking the image results in each handler emitting a console
message that identifies the path of the event.
message that identifies the path of the event.