2010-09-16 17:13:38 +00:00
<!DOCTYPE html>
2010-11-02 01:46:29 +00:00
< html lang = 'en' > < head >
2011-02-18 20:00:18 +00:00
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, minimum-scale=1, maximum-scale=1" > < meta http-equiv = 'content-type' content = 'text/html; charset=UTF-8' / > < / head > < body >
2010-09-18 16:20:35 +00:00
< div data-role = "page" >
2010-09-21 14:58:54 +00:00
< div data-role = "header" >
2010-09-16 17:13:38 +00:00
< h1 > .undelegate()< / h1 >
< / div >
2010-10-12 19:50:28 +00:00
< div data-role = "content" data-theme = "c" id = "undelegate1" >
2010-09-16 17:13:38 +00:00
< h2 class = "jq-clearfix roundTop section-title" >
< span class = "name" > .undelegate( )< / span > < span class = "returns" > Returns: < a class = "return" href = "http://docs.jquery.com/Types#jQuery" > jQuery< / a > < / span >
< / h2 >
< div class = " entry-details" >
< p class = "desc" > < strong > Description: < / strong > Remove a handler from the event for all elements which match the current selector, now or in the future, based upon a specific set of root elements.< / p >
< ul class = "signatures" >
< li class = "signature" id = "undelegate" > < h4 class = "name" >
< span class = "versionAdded" > version added: < a href = "/category/version/1.4.2/" > 1.4.2< / a > < / span > .undelegate()< / h4 > < / li >
< li class = "signature" id = "undelegate-selector-eventType" >
< h4 class = "name" >
< span class = "versionAdded" > version added: < a href = "/category/version/1.4.2/" > 1.4.2< / a > < / span > .undelegate( selector, eventType )< / h4 >
< p class = "arguement" > < strong > selector< / strong > A selector which will be used to filter the event results.< / p >
< p class = "arguement" > < strong > eventType< / strong > A string containing a JavaScript event type, such as "click" or "keydown"< / p >
< / li >
< li class = "signature" id = "undelegate-selector-eventType-handler" >
< h4 class = "name" >
< span class = "versionAdded" > version added: < a href = "/category/version/1.4.2/" > 1.4.2< / a > < / span > .undelegate( selector, eventType, handler )< / h4 >
< p class = "arguement" > < strong > selector< / strong > A selector which will be used to filter the event results.< / p >
< p class = "arguement" > < strong > eventType< / strong > A string containing a JavaScript event type, such as "click" or "keydown"< / p >
< p class = "arguement" > < strong > handler< / strong > A function to execute at the time the event is triggered.< / p >
< / li >
< / ul >
< div class = "longdesc" > < p > Undelegate is a way of removing event handlers that have been bound using < a href = "/delegate" > .delegate()< / a > . It works virtually identically to < a href = "/die" > .die()< / a > with the addition of a selector filter argument (which is required for delegation to work).< / p > < / div >
< h3 > Examples:< / h3 >
< div id = "entry-examples" class = "entry-examples" >
< div id = "example-0" >
< h4 > Example: < span class = "desc" > Can bind and unbind events to the colored button.< / span >
< / h4 >
< pre > < code class = "example demo-code" > < !DOCTYPE html>
< html>
< head>
< style>
button { margin:5px; }
button#theone { color:red; background:yellow; }
< /style>
< script src="http://code.jquery.com/jquery-latest.js"> < /script>
< /head>
< body>
< button id="theone"> Does nothing...< /button>
< button id="bind"> Bind Click< /button>
< button id="unbind"> Unbind Click< /button>
< div style="display:none;"> Click!< /div>
< script>
function aClick() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
$("body").delegate("#theone", "click", aClick)
.find("#theone").text("Can Click!");
});
$("#unbind").click(function () {
$("body").undelegate("#theone", "click", aClick)
.find("#theone").text("Does nothing...");
});
< /script>
< /body>
< /html> < / code > < / pre >
< h4 > Demo:< / h4 >
< div class = "demo code-demo" > < / div >
< / div >
< div id = "example-1" >
< h4 > Example: < span class = "desc" > To unbind all delegated events from all paragraphs, write:< / span >
< / h4 >
< pre > < code class = "example" > $("p").undelegate()< / code > < / pre >
< / div >
< div id = "example-2" >
< h4 > Example: < span class = "desc" > To unbind all delegated click events from all paragraphs, write:< / span >
< / h4 >
< pre > < code class = "example" > $("p").undelegate( "click" )< / code > < / pre >
< / div >
< div id = "example-3" >
< h4 > Example: < span class = "desc" > To undelegate just one previously bound handler, pass the function in as the third argument:< / span >
< / h4 >
< pre > < code class = "example" > var foo = function () {
// code to handle some kind of event
};
$("body").delegate("p", "click", foo); // ... now foo will be called when paragraphs are clicked ...
$("body").undelegate("p", "click", foo); // ... foo will no longer be called.< / code > < / pre >
< / div >
< / div >
< / div >
< / div >
< / div >
< / body > < / html >