JavaScripture
Contribute via GitHub Feedback

EventTarget : Object

EventTargets are Objects that fire events. EventTargets usually expose an onevent property for each event where you can assign a Function to be called when the event fires. You can also use addEventListener() to hook up multiple listeners to the same event.

Instance Methods

addEventListener 4 variants
addEventListener(type : String, listener : Function, [useCapture : Boolean]) : undefined
listener(event : Event) : undefined

Adds listener to the list of callbacks called when the specified event is fired. If useCapture is true, listener will be called in the capture phase of the event routing (ie, during the walk down the tree to the target instead of on the way up after firing on the target). Unlike using the onevent style of listening to events, addEventListener allows more than one listener to be associated with the event. Use removeEventListener() to stop listening to the event.

Example:

Run

Results:

 

addEventListener(type : String, listener : EventListener, [useCapture : Boolean]) : undefined

addEventListener(type : String, listener : Function, options : Object) : undefined
listener(event : Event) : undefined
options : {
capture :Booleancall listener in the capture phase
once :Booleanremove listener after firing
passive :Booleanset to true if you'll never call event.preventDefault(). Allows browser to provide perf optimizations like smoother scrolling.
}

addEventListener(type : String, listener : EventListener, options : Object) : undefined
options : {
capture :Booleancall listener in the capture phase
once :Booleanremove listener after firing
passive :Booleanset to true if you'll never call event.preventDefault(). Allows browser to provide perf optimizations like smoother scrolling.
}

dispatchEvent(event : Event) : Boolean

Raises event on this. If event.bubbles is true, and this is an Node, the event will propagate through the ancestor hierarchy.

Example:

Run

Results:

 

removeEventListener 4 variants
removeEventListener(type : String, listener : Function, [useCapture : Boolean]) : undefined
listener(event : Event) : undefined

removeEventListener(type : String, listener : EventListener, [useCapture : Boolean]) : undefined

removeEventListener(type : String, listener : Function, options : Object) : undefined
listener(event : Event) : undefined
options : {
capture :Booleanremoves the listener hooked to the capture phase
}

removeEventListener(type : String, listener : EventListener, options : Object) : undefined
options : {
capture :Booleanremoves the listener hooked to the capture phase
}

Details

EventTarget can also be used as a base class to provide event handling for user defined types.

Example:

Run

Results: