Web APIs

EventTarget.addEventListener()

Try the free JavaScript compiler

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

NameTypeDescription
typestringEvent name.
callbackfunction | EventListener object | nullListener callback.
optionsboolean | objectCapture 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);
JavaScript Reference