- Instant help with your JavaScript coding problems
addEventListener
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
JavaScript:
addEventListener(type, listener);
TypeScript:
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
Examples:
element.addEventListener('click', (evt) => {
    console.log('Clicked');
});

Related snippets