{"name":"undelegate","type":"method","title":".undelegate()","deprecated":null,"removed":null,"desc":"Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.","categories":["events/event-handler-attachment","version/1.4.2","version/1.4.3","version/1.6"],"entries":[{"return":"jQuery","signatures":[{"added":"1.4.2"},{"added":"1.4.2","argument":[{"desc":"A selector which will be used to filter the event results.","name":"selector","type":"String"},{"desc":"A string containing a JavaScript event type, such as \"click\" or \"keydown\"","name":"eventType","type":"String"}]},{"added":"1.4.2","argument":[{"desc":"A selector which will be used to filter the event results.","name":"selector","type":"String"},{"desc":"A string containing a JavaScript event type, such as \"click\" or \"keydown\"","name":"eventType","type":"String"},{"desc":"A function to execute at the time the event is triggered.","name":"handler(eventObject)","type":"Function"}]},{"added":"1.4.3","argument":[{"desc":"A selector which will be used to filter the event results.","name":"selector","type":"String"},{"desc":"An object of one or more event types and previously bound functions to unbind from them.","name":"events","type":"PlainObject"}]},{"added":"1.6","argument":{"desc":"A string containing a namespace to unbind all events from.","name":"namespace","type":"String"}}],"examples":[{"desc":"Can bind and unbind events to the colored button.","code":"\nfunction aClick() {\n $( \"div\" ).show().fadeOut( \"slow\" );\n}\n$( \"#bind\" ).click(function() {\n $( \"body\" )\n .delegate( \"#theone\", \"click\", aClick )\n .find( \"#theone\" ).text( \"Can Click!\" );\n});\n$( \"#unbind\" ).click(function() {\n $( \"body\" )\n .undelegate( \"#theone\", \"click\", aClick )\n .find( \"#theone\" ).text( \"Does nothing...\" );\n});\n","css":"\n button {\n margin: 5px;\n }\n button#theone {\n color: red;\n background: yellow;\n }\n","html":"\n\n\n\n
\n"},{"desc":"To unbind all delegated events from all paragraphs, write:","code":"\n$( \"p\" ).undelegate();\n"},{"desc":"To unbind all delegated click events from all paragraphs, write:","code":"\n$( \"p\" ).undelegate( \"click\" );\n"},{"desc":"To undelegate just one previously bound handler, pass the function in as the third argument:","code":"\nvar foo = function () {\n // Code to handle some kind of event\n};\n\n// ... Now foo will be called when paragraphs are clicked ...\n$( \"body\" ).delegate( \"p\", \"click\", foo );\n\n// ... foo will no longer be called.\n$( \"body\" ).undelegate( \"p\", \"click\", foo );\n"},{"desc":"To unbind all delegated events by their namespace:","code":"\nvar foo = function() {\n // Code to handle some kind of event\n};\n\n// Delegate events under the \".whatever\" namespace\n$( \"form\" ).delegate( \":button\", \"click.whatever\", foo );\n\n$( \"form\" ).delegate( \"input[type='text'] \", \"keypress.whatever\", foo );\n\n// Unbind all events delegated under the \".whatever\" namespace\n$( \"form\" ).undelegate( \".whatever\" );\n"}],"longdesc":"\nThe .undelegate() method is a way of removing event handlers that have been bound using .delegate(). As of jQuery 1.7, the .on() and .off() methods are preferred for attaching and removing event handlers.