16

Is it possible to see (debug) custom events being fired from DOM elements in the browser?

Let's say I want to see which specific element of the Bootstrap Collapse fires the show.bs.collapse event, can I somehow see it for instance in Chrome dev tools?

0

3 Answers 3

9
+50

First off, Monitor Events will handle this for normal JS events. However, Bootstrap events are jQuery events, so vanilla JS event listeners don't listen for them.

To listen to jQuery events run the following code snippet in your console: jQuery('body').bind("show.bs.collapse", function(e){console.log(e);});

Replace "shown.bs.collapse" with whatever event you want. When they are logged, just check the target element for the event to know what fired it.

Now, for the other way around, to see what is listening to events. Within the elements panel, if you go to the event listener tab and uncheck "ancestors", then you will see only the directly bound event listeners on an element. This way you know what is listening for the event so you can inspect what should be done when it is fired. This matters, since you may find 'body' isn't getting the event, since it could have bubbling cancelled. So if the above snippet isn't working, you need to check for bubble cancelling in the element listening for the event.

Showing direct event listeners

Sign up to request clarification or add additional context in comments.

Comments

2

Firefox offers out of the box, listeners for jQuery events, https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Examine_event_listeners

But you can extend it: http://flailingmonkey.com/view-jquery-and-jquery-live-events-in-firefox-devtools/

Comments

2

You can use Visual Event 2 bookmarklet. Great tool used to inspect which events are attached to a specific DOM elements.

1 Comment

There is a chrome extension as well which uses the same code chrome.google.com/webstore/detail/visual-event/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.