Web APIs
EventTarget.addEventListener()
Registers a callback for an event type. Capture, once, passive and signal may be specified in an options object.
Formal Syntax & Structure
javascript syntaxjavascript
target.addEventListener(type, callback, options?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| type | string | Event name. |
| callback | function | EventListener object | null | Listener callback. |
| options | boolean | object | Capture flag or listener options. |
Return Value
undefined
No return value.
Working Example
Example Snippetjavascript
const b=document.createElement("button");let n=0;const hit=()=>n++;b.addEventListener("click",hit);b.addEventListener("click",hit);b.click();console.log(n);