Is there a posibility to retrieve handlers registered on click event, if they have been registered via javascript ? I have an element with empty onclick atribute, but on input click event some js handler is executed, and I need to get the handler.
-
See: http://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node – Diodeus - James MacFarlane Sep 22 '11 at 17:09
1 Answers
First, check for an onsubmit handler on your form. That would fire when the button is clicked.
Programatically, you can't discover event handlers registered via element.addEventListener() or element.attachEvent(), unless registered via a library that exposes such handlers.
However, you can discover all event handlers in Google Chrome's DOM inspector. In Chrome, hit f12 to open up the developer tools. On the "Elements" tab, find your button and click to select it. Then on the right, click to expand the "Event Listeners" section. There you will find a list of all event listeners. Enjoy!
I know of no such trick in FireBug or in IE's developer tools.
You could also try the Visual Event Bookmarklet which works well unless, as I mentioned above, the event handlers are registered via element.addEventListener() or element.attachEvent(). If that's the case, and Chrome isn't good enough, your best bet would be to crack open your favorite JavaScript debugger, pause script execution and click the button. Hopefully, the script will break in the click handler.
- 87,962
- 25
- 144
- 176