Discovering the events attached to elements in jQuery

If you have a need to find what events are attached to an element in jQuery, here’s what you do:

Finding events attached to the document:

jQuery._data( jQuery( document )[0], 'events' );

Finding events attached to an element with an ID of bacon:

jQuery._data( jQuery( '#bacon' )[0], 'events' );

Here’s a snippet I’ve been using in the console:

var events = jQuery._data( jQuery( document )[0], 'events' );
for ( var i in ) {
  console.log( 'click ' + i + ' :: ' +[ i ].selector );