Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to find the event handlers of an element with Javascript?

Say you have this div:

<div id="foo">bar</div>

And you do this:

$("#foo").click(someFunction);

somewhere inside your Javascript code.

Once the page has been loaded, is there a way to find out, via firebug or inspect element in Chrome, or anything else, that the click event for #foo is bound to someFunction? I.e., find this out without having to look through all your code?

like image 742
Ali Avatar asked Aug 08 '12 11:08

Ali


People also ask

How do you find the event listener of an element?

Right-click on the search icon button and choose “inspect” to open the Chrome developer tools. Once the dev tools are open, switch to the “Event Listeners” tab and you will see all the event listeners bound to the element. You can expand any event listener by clicking the right-pointing arrowhead.

Are the event handlers in JavaScript?

JavaScript Event HandlersEvent handlers can be used to handle and verify user input, user actions, and browser actions: Things that should be done every time a page loads. Things that should be done when the page is closed. Action that should be performed when a user clicks a button.

How do you find out which JavaScript Events fired?

Open Google Chrome and press F12 to open Dev Tools. Go to Event Listener Breakpoints, on the right: Click on the events and interact with the target element.

How are event handlers invoked in JavaScript?

This event handler invokes a JavaScript code when we place the mouse over a specific link or an object. This event handler invokes a JavaScript code when the mouse leaves a particular link or an object.


1 Answers

Chrome Developer tools does this.

  1. right click an element
  2. click inspect element
  3. in the right hand column, scroll down to event listeners

This will give you a list of event listeners on the object that can be expanded to find their source and the attached function.

Firebug has this information under the DOM tab, but it's less user friendly.

like image 141
ColBeseder Avatar answered Sep 23 '22 00:09

ColBeseder