Is there a way to find out which Javascript function is fired by click on a certain button?
Let me explain ...
I have a web page with a large js script (not made by me), I've to detect which function is triggered by a specific button, I need to find the function triggered by this button.
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.
This is available in all major browsers in the developer tools (usually press F12 to open). In Chrome, for example, right click on the element, inspect element. Then expand the 'Event Listeners' tab on the righthand side, find 'click' and expand that.
Use Chrome's Web Inspector to inspect the element and check out the Event Listeners panel.
If the code attaching the event is in a library (for example, by Zepto in my example), set a breakpoint on the line and examine the call stack to see where it originated in your code.
As you can see, the event has originated in my code and now I know the filename and line number.
Inside your functions, you can put arguments.callee
to know about it. Notice that this is deprecated but should tell you what you are looking for.
alert(arguments.callee);
In Google Chrome, open your web page of interest.
Right-click on the element(i.e a button) you want to inspect. In the 'context menu' that appears, click 'Inspect'. A 'Developer tools' window will appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With