Skip to content

HTMLElement.off method

HTMLElement › off

Official

Removes an event listener from the element.

Signature:

off(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => unknown, options?: boolean | AddEventListenerOptions | undefined): void

Parameters:

ParameterTypeDescription
thisHTMLElementThe element to remove the event listener from.
typeKThe type of event to listen for.
selectorstringThe selector of the event target.
listener(this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => unknownThe listener to call when the event is triggered.
options?boolean | AddEventListenerOptions | undefinedThe options of the event listener.

Returns: void

Example:

document.body.off('click', 'div', document.body._EVENTS.click[0].listener);