2

This is purely for debugging purposes. Is there a single command like:

addEventListener('*', myHandler) 

in native js or:

$(document).on('*', myHandler)

in jQuery that would listen for any event no matter what type or namespace and call myHandler when an event happens?

Or is there something in the browser's own devtools that might let you see all the events?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
TxRegex
  • 2,347
  • 21
  • 20
  • 1
    Well, take a look at [this previously asked question](http://stackoverflow.com/questions/5848598/jquery-how-can-i-bind-all-events-on-a-dom-element) – Eric Jan 02 '14 at 19:33
  • No, because there is no possible use for doing so. Even when debugging it isn't useful to see **all** types of events; you typically only need to see the ones relevant to whatever you're doing, which will be a small subset. – user229044 Jan 02 '14 at 19:36

1 Answers1

7

Chrome's dev tools can do this. Open them up, go to the Sources tab, and look in the right-hand column with the expandable/collapsible sub-panes. Expand the one called Event Listener Breakpoints. Under here are expandable checkbox selections that allow you to tick any events that you wish to listen for. Once you check any of them, Chrome will break in JS code as soon as an event of that type occurs.

Assuming your myHandler function contains code you just want to execute for debugging, you can just run this code in the console, or call the function via console.

enter image description here

ajp15243
  • 7,704
  • 1
  • 32
  • 38