addEventListener method
Registers an event handler for the specified event type.
![]() ![]() |
Syntax
object.addEventListener(type, listener, useCapture)Parameters
- type [in]
-
Type: String
The type of event type to register.
- listener [in]
-
C++ The event handler function to associate with the event. Be aware that the event handler function itself requires two parameters - the first is the event target (that is, the object on which the event handler function is being invoked) and the second is the IDOMEvent object. JavaScript The event handler function to associate with the event. - useCapture [in]
-
Type: Boolean
A Boolean value that specifies the event phase to add the event handler for:
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Standards information
Remarks
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.
If you register multiple identical event handlers on the same event target, the duplicate event handlers are discarded.
Examples
The following code example demonstrates the difference between the capturing and bubbling event phases.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/ie9_event_phases.htm
See also
- window
- AudioTrackList
- ApplicationCache
- CryptoOperation
- document
- IDBDatabase
- IDBRequest
- IDBTransaction
- MSInputMethodContext
- KeyOperation
- MediaSource
- MessagePort
- Node
- Screen
- SourceBuffer
- SourceBufferList
- SVGElementInstance
- TextNode
- TextTrack
- TextTrackCue
- TextTrackList
- WebSocket
- Window
- Window
- WorkerGlobalScope
- XMLHttpRequest
- removeEventListener

