Created
April 25, 2015 15:42
-
-
Save NickCraver/c5a8e14920b282940ffd to your computer and use it in GitHub Desktop.
A simple jQuery plugin to print bound event handlers, including on parent elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.logHandlers = function() { | |
var result = {}; | |
this.parents().andSelf().each(function(_, e) { | |
var events = $._data(e, 'events') || {}; | |
if ($.isEmptyObject(events)) return; | |
var cur = result[this.outerHTML.split($(this).html())[0]] = {}; | |
Object.keys(events).forEach(function(k) { | |
cur[k] = events[k].map(function(ev) { | |
return ev.handler.toString(); | |
}); | |
}); | |
}); | |
console.dir(result); | |
// Note: explicitly NOT doing "return this;" as a normal plugin would because the main use is from the console | |
// return this; would re-print the original elements in their own array, cluttering results | |
}; | |
// Example usage on Stack Overflow: $(".topbar-icon").logHandlers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment