Search code examples
javascripteventsprototypejslistenerobserver-pattern

Update: How to find event listeners on a DOM node in prototype?


I'm looking for an updated answer to this question.

It seems that Event.observers is no longer used (perhaps to avoid memory leaks) in Prototype 1.6+, so how do I track down now what event listeners are attached to an element?

I know Firebug has a "break on next" button, but there are several mouse listeners on the body element that execute before I can get to the behavior that I want on another particular element, so is there some other way?


Solution

  • I've update the answer you linked to with more comprehensive Prototype coverage accounting for changes in versions 1.6.0 to 1.6.1.

    It got very messy in between there, but 1.6.1 is somewhat clean:

    var handler = function() { alert('clicked!') };
    $(element).observe('click', handler);
    
    // inspect
    var clickEvents = element.getStorage().get('prototype_event_registry').get('click');
    clickEvents.each(function(wrapper){
        alert(wrapper.handler) // alerts "function() { alert('clicked!') }"
    })