Reputation: 92752
Is there a way to find what event handlers are attached to a given DOM node?
For example, when you click the "add comment" link, there's an event handler attached to it which shows the comment form. Now, if I have a DOM document (a web page), and want to list all the event handlers for one specific node, is there a way to do this?
(I suspect that it's not possible for JS running within the page; do browser extensions in FF have access to this data?)
Upvotes: 13
Views: 11589
Reputation: 20439
In Chrome, you can use getEventListeners
.
getEventListeners($0)
An object mapping event names to their handlers should be returned. Note that $0
is a special dev tools variable which always points to the last element selected in the "Elements" tabs.
Upvotes: 9
Reputation: 7199
In Chrome:
This will show you what event handlers are attached to that element.
(Krof's answer could have been more clearly written.)
Upvotes: 1
Reputation: 19841
Chrome (and I suspect Safari) can show attached event listeners when you select an element in the DOM and then scroll down the right sidebar to the Event Listeners section. There, you can see which functions are attached.
I don't have a copy of Firebug at the moment, but I suspect the DOM tab to show similar information in Firefox as well.
Upvotes: 12