can.undelegate
Stop listening for events from the children of an element.
can.undelegate.call(element, selector, eventName, handler)
Parameters
-
element
{HTMLElement}
The HTML element to unbind from.
-
selector
{String}
A selector for delegating downward.
-
eventName
{String}
The name of the event to listen for.
-
handler
{function()}
The function that was bound.
Returns
{Object}
The element.
can.undelegate(selector, eventName, handler)
unbinds a delegate handler
on an object for a given event. It works on:
- HTML elements and the window
The idea is that undelegate can be used on anything that produces delegate events
and it will figure out the appropriate way to
bind to it. Typically, can.undelegate
is only used internally to
CanJS; however, if you are making libraries or extensions, use
can.undelegate
to stop listening to events independent of the underlying library.
Delegate/undelegate binding to an HTMLElement
// Assuming an HTML body like the following:
// <div id="parent">
// <div class="child">Hello</div>
// </div>
var el = document.getElementById('parent');
var handler = function(ev) {
return this; //-> el
};
can.delegate.call(el, ".child", "click", handler);
can.undelegate.call(el, ".child", "click", handler);