Document.on method
Document › on
Official
Adds an event listener to the document.Signature:
on(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => unknown, options?: boolean | AddEventListenerOptions | undefined): voidParameters:
| Parameter | Type | Description |
|---|---|---|
| this | Document | The document to add the event listener to. |
| type | K | The type of event to listen for. |
| selector | string | The selector of the event target. |
| listener | (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => unknown | The listener to call when the event is triggered. |
| options? | boolean | AddEventListenerOptions | undefined | The options of the event listener. |
Returns: void
Example:
document.on('click', 'div', (ev) => { console.log(ev);});