Skip to content

ElementWrapper.off()

Definition

ts
off<K extends keyof HTMLElementEventMap>(
    event: K,
    callback: EventCallback<T, HTMLElementEventMap[K]>,
): this;
off(event: string, callback: EventCallback<T>): this;

Description

Removes a previously added event listener from all selected elements.

The callback function is of type EventCallback.

The callback reference must match the one originally passed to .on() — anonymous functions cannot be removed this way.

Example

ts
function handleClick() {
  console.log('Clicked!');
}
 
$('.btn').on('click', handleClick);
 
// Later, remove the listener
$('.btn').off('click', handleClick);