Jquery turning “on” and “off” event handlers

eventsjquery

How would I apply the "off" directive to a named handler?

ex

var $btn = $("#theBtn");
var namedHandler = $btn.on("click", function() {
//do something
//then turn off
})

would I turn it off like this

$btn.off("click");

or could I do something else now it is stored in a variable?

namedHandler.off("click");

or

namedHandler.off();

etc.

Any pointers much appreciated.

Best Solution

You can also do this

function handleClick(event) 
{
    // code
}

$('#btn').on('click', handleClick);

$('#btn').off('click', handleClick);

Some usefull examples only about on/off here.