Skip to content

Component.registerDomEvent method

Component › registerDomEvent

Official

Registers a DOM event to be detached when unloading.

Signature:

registerDomEvent(el: Document, type: K, callback: (this: HTMLElement, ev: DocumentEventMap[K]) => unknown, options?: AddEventListenerOptions | boolean): void

Parameters:

ParameterTypeDescription
elDocumentThe element to register the event on.
typeKThe type of the event to register.
callback(this: HTMLElement, ev: DocumentEventMap[K]) => unknownThe callback to be called when the event is triggered.
options?AddEventListenerOptions | booleanThe options for the event.

Returns: void

Since: 0.14.8

Example:

component.registerDomEvent(document, 'click', () => {
console.log('Document clicked');
});

Official

Registers a DOM event to be detached when unloading.

Signature:

registerDomEvent(el: HTMLElement, type: K, callback: (this: HTMLElement, ev: HTMLElementEventMap[K]) => unknown, options?: AddEventListenerOptions | boolean): void

Parameters:

ParameterTypeDescription
elHTMLElementThe element to register the event on.
typeKThe type of the event to register.
callback(this: HTMLElement, ev: HTMLElementEventMap[K]) => unknownThe callback to be called when the event is triggered.
options?AddEventListenerOptions | booleanThe options for the event.

Returns: void

Example:

component.registerDomEvent(document.body, 'click', () => {
console.log('Body clicked');
});

Official

Registers a DOM event to be detached when unloading.

Signature:

registerDomEvent(el: Window, type: K, callback: (this: HTMLElement, ev: WindowEventMap[K]) => unknown, options?: AddEventListenerOptions | boolean): void

Parameters:

ParameterTypeDescription
elWindowThe element to register the event on.
typeKThe type of the event to register.
callback(this: HTMLElement, ev: WindowEventMap[K]) => unknownThe callback to be called when the event is triggered.
options?AddEventListenerOptions | booleanThe options for the event.

Returns: void

Example:

component.registerDomEvent(window, 'click', () => {
console.log('Window clicked');
});