Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Created April 17, 2014 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedamage/11011183 to your computer and use it in GitHub Desktop.
Save mikedamage/11011183 to your computer and use it in GitHub Desktop.
/**
* Innovate Debug Functions
*/
/**
* Descends through an element's children, their children's children, etc. and
* prints a list of their bound event handlers to console.
*
* ex. $('.sub-nav').parent().boundEventsTree();
*/
$.fn.boundEventsTree = function jqBoundEventsTree() {
var $kids = this.children();
$kids.each(function() {
var $elem = $(this), evts = $._data($elem[0], 'events');
if (evts) { console.log(this, evts); }
$elem.boundEventsTree(); // recurse
});
return this;
};
/**
* Watches literally everything that's a child of an element for the specified events
* and reports to console when they fire.
*
* ex. $('body').watchEverything('mouseenter mouseleave');
*/
$.fn.watchEverything = function watchEverything(evts) {
this.on(evts, '*', function(evt) {
console.log(evt.type, evt.target, evt);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment