← Back to Index

.off()

Remove an event handler.

Examples

1. Remove all events of a type

$('button').off('click');

Result

// All 'click' listeners are removed from buttons.

2. Remove specific handler

function onClick() { console.log('Clicked'); }
$('button').on('click', onClick);
$('button').off('click', onClick);

Result

// Specifically removes the `onClick` listener.
// Other click listeners remain intact.

3. Remove namespaced event

$('button').off('click.myPlugin');

Result

// Removes only click events with namespace "myPlugin".

Parameters

Parameter Type Description
eventType string One or more space-separated event types.
selector string Optional. A selector which should match the one originally passed to .on().
handler function Optional. A handler function previously attached for the event(s).

Returns: The original SR object for chaining.