Registers an event handler for the specified event type.
Syntaxobject.addEventListener(type, listener, useCapture)
- type [in]
The type of event type to register.
- listener [in]
- useCapture [in]
A Boolean value that specifies the event phase to add the event handler for:
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Events are handled in two phases: capturing and bubbling. During the capturing phase, events are dispatched to parent objects before they are dispatched to event targets that are lower in the object hierarchy. During the bubbling phase, events are dispatched to target elements first and then to parent elements. You can register event handlers for either event phase. For more information, see eventPhase.
Note Some events, such as onfocus, do not bubble. However, you can capture all events. You cannot capture events by elements that are not parents of the target element.
If you register multiple identical event handlers on the same event target, the duplicate event handlers are discarded.
The following code example demonstrates the difference between the capturing and bubbling event phases.