6

How can I access events added with attachEvent() / addEventListener() in JavaScript?

Use case: debug events using FireBug's console.

cllpse
  • 21,396
  • 37
  • 131
  • 170

3 Answers3

5

There is no way to access them.

Depending on what you're trying to achieve, better way to debug the events might be to output the event properties you're interested in from the event handler function...

kkyy
  • 12,214
  • 3
  • 32
  • 27
0

If you always add and remove handlers with a custom method, you can maintain a log of them in the same method. It adds some overhead to do so.

For example, here is a piece that concerns IE-

//Run=window.Run || {Shadow:{},nextid:0};

else if(window.attachEvent){    
    Run.handler= function(who, what, fun){
        if(who.attachEvent){

            who.attachEvent('on'+what, fun);

            var hoo=who.id || who.tagName+(++Run.nextid);
            if(!Run.Shadow[hoo])Run.Shadow[hoo]={};
            if(!Run.Shadow[hoo][what])Run.Shadow[hoo][what]=[];
            Run.Shadow[hoo][what].push(fun);
        }
    }
}
kennebec
  • 102,654
  • 32
  • 106
  • 127
  • What is the purpose of who.tagName+(++Run.nextid) line? Do actually use this log later on to release handlers? – jayarjo Dec 22 '10 at 10:22
0

I know in jQuery (before version 1.8) you can do something like

$element.data('events')

And using fireQuery you can actually see the handlers in HTML tab like this

Also see this

Community
  • 1
  • 1
Aamir Afridi
  • 6,364
  • 3
  • 42
  • 42