2

addEventListener lets me add one listener to a target associated with some event type.

Can I somehow listen to all the events emitted by a target? Every time a specified object emits an event - any event - I want to log the type of the event.

John Hoffman
  • 17,857
  • 20
  • 58
  • 81
  • 2
    Related: [How do you log all events fired by an element in jQuery?](http://stackoverflow.com/questions/7439570/how-do-you-log-all-events-fired-by-an-element-in-jquery) – Ram Aug 26 '14 at 21:02
  • Related: [Is it possible to programmatically catch all events on the page in the browser?](http://stackoverflow.com/questions/5107232/is-it-possible-to-programmatically-catch-all-events-on-the-page-in-the-browser) – Ram Aug 26 '14 at 21:04
  • I don't think there is any "generic" event to handle all the others, but maybe you can search for an object which lists all the possible events ? I don't know if there is a way to read the [GlobalEventHandlers](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers) interface. – Sebastien C. Aug 26 '14 at 21:35

1 Answers1

1

Using jQuery you could bind all the standard JavaScript events using:

$('#element').bind('blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup  mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error', function(event) {
    console.log(event.type);
}
Zak
  • 1,910
  • 3
  • 16
  • 31