-
unbind( String type , Function data ) returns jQuery
This does the opposite of bind, it removes bound events from each of the matched elements.
<p>Without any arguments, all bound events are removed.</p><p>You can also unbind custom events registered with bind.</p><p>If the type is provided, all bound events of that type are removed.</p><p>If the function that was passed to bind is provided as the second argument, only that specific event handler is removed.</p>Example:
Can bind and unbind events to the colored button.
function aClick() { $("div").show().fadeOut("slow"); } $("#bind").click(function () { // could use .bind('click', aClick) instead but for variety... $("#theone").click(aClick) .text("Can Click!"); }); $("#unbind").click(function () { $("#theone").unbind('click', aClick) .text("Does nothing..."); });HTML:
<button id="theone">Does nothing...</button> <button id="bind">Bind Click</button> <button id="unbind">Unbind Click</button> <div style="display:none;">Click!</div>Example:
To unbind all events from all paragraphs, write:
$("p").unbind()Example:
To unbind all click events from all paragraphs, write:
$("p").unbind( "click" )Example:
To unbind just one previously bound handler, pass the function in as the second argument:
var foo = function () { // code to handle some kind of event }; $("p").bind("click", foo); // ... now foo will be called when paragraphs are clicked ... $("p").unbind("click", foo); // ... foo will no longer be called. -
unload( Function fn ) returns jQuery
Binds a function to the unload event of each matched element.
Example:
To display an alert when a page is unloaded:
$(window).unload( function () { alert("Bye now!"); } );