jQuery .off() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Event Handler

Definition

.off(events [, selector] [, handler]) removes handlers attached with .on() (since 1.7). Filter by event type, namespace, delegation selector, and/or function reference.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#btn").on("click", fn);
$("#btn").off("click", fn);          // remove that handler

$("body").on("click", "#theone", flash);
$("body").off("click", "#theone", flash); // same selector required

$("form").off(".validator");         // all handlers in that namespace
$("p").off();                        // remove everything on p
$("p").off("click", "**");           // all delegated clicks only
CallWhat it does
.off()Remove all handlers on the element(s)
.off(events [, selector] [, handler])Filter by type / namespace / selector / function
.off(eventsObject [, selector])Map of event → handler (or false)
.off(event)Remove using a jQuery.Event object

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
events [Used in .off(events [, selector] [, handler]). Filter by type / namespace / selector / function
selector] [Used in .off(events [, selector] [, handler]). Filter by type / namespace / selector / function
handler]Used in .off(events [, selector] [, handler]). Filter by type / namespace / selector / function
eventsObject [Used in .off(eventsObject [, selector]). Map of event → handler (or false)
selector]Used in .off(eventsObject [, selector]). Map of event → handler (or false)

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Delegated Bind / Off

Attach a delegated click, then remove it with the same selector.

jQuery
function flash() {
  $("#out").text("Clicked!");
}

$("#bind").on("click", function () {
  $("body").on("click", "#theone", flash);
  $("#theone").text("Can Click!");
});

$("#unbind").on("click", function () {
  $("body").off("click", "#theone", flash);
  $("#theone").text("Does nothing...");
});
Try It Yourself

How It Works

  1. On. Handler lives on body, filtered by #theone.
  2. Click. Matching clicks bubble up and run flash.
  3. Off. Same event, selector, and function remove that entry.

Example 2 — Remove All Handlers

No arguments — wipe every handler on the matched elements.

jQuery
$("p").on("click", fn1);
$("p").on("mouseover", fn2);

$("p").off(); // both gone
Try It Yourself

How It Works

  1. Attach. Multiple event types on the same elements.
  2. Broad off. Empty .off() clears all of them.
  3. Use. Handy for teardown; risky for shared elements.

Example 3 — Remove One Handler Function

Pass the same function reference you used with .on().

jQuery
var foo = function () {
  $("#out").text("foo ran");
};

$("body").on("click", "p", foo);
$("body").off("click", "p", foo);
Try It Yourself

How It Works

  1. Named fn. Keep a stable function reference.
  2. On. Bind that exact function.
  3. Off. Pass the same function as the third argument.

Frequently Asked Questions

.off() removes event handlers attached with .on(). Since jQuery 1.7 it is the standard unbind API for both direct and delegated handlers, replacing .unbind(), .undelegate(), and .die().
It removes all handlers from the matched elements — direct and delegated. Prefer narrower filters (event type, namespace, selector, or handler) unless you are tearing a widget down.
Pass the same selector you used with .on(). Example: $(body).on("click", "#theone", fn) then $(body).off("click", "#theone", fn). A mismatched selector will not remove it.
$(el).off("click", "**") removes all delegated click handlers from el without removing direct click handlers bound on el itself.
Namespaces such as click.myPlugin let you remove only your handlers with .off(".myPlugin") without touching other code. Best practice for plugins and large apps.
.unbind() only covered direct binds; .die() only removed .live() handlers (both legacy). .off() works with everything attached via .on(), including delegation.

Next: .bind() Method

See the legacy direct-bind API that .on() replaced.

.bind() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful