Example 1 — Delegated Bind / Off
Attach a delegated click, then remove it with the same selector.
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...");
}); How It Works
- On. Handler lives on
body, filtered by#theone. - Click. Matching clicks bubble up and run
flash. - Off. Same event, selector, and function remove that entry.

