can.undelegate

  • function
 

Stop listening for events from the children of an element.

can.undelegate.call(element, selector, eventName, handler)

Parameters

  1. element {HTMLElement}

    The HTML element to unbind from.

  2. selector {String}

    A selector for delegating downward.

  3. eventName {String}

    The name of the event to listen for.

  4. 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 listen to events independent of the underlying library.

Delegate/undelegate binding to an HTMLElement

var el = document.getElementById('foo'),
handler = function(ev){
    this // el
};
can.delegate.call(el, ".selector", "click", handler)
can.undelegate.call(el, ".selector", "click", handler)