Skip to content

Instantly share code, notes, and snippets.

@MohamedAlaa
Forked from zkareemz/jquery-attached-events
Last active April 6, 2017 14:10
Show Gist options
  • Save MohamedAlaa/31c5bc3f47fda69765f4 to your computer and use it in GitHub Desktop.
Save MohamedAlaa/31c5bc3f47fda69765f4 to your computer and use it in GitHub Desktop.
// This is a simple function to get all the attached jquery events on all the DOM elements
// you will find a new data attribute on the elements that has events attached to it.
(function() {
if (window.jQuery) {
var elms = [],
elm = {},
attrs = "",
evTypes = 0,
evCounter = 0,
elmCounter = 0,
attrName = "data-attached-events";
jQuery.each($("*"), function() {
elmCounter++;
elm = this;
evt = jQuery._data(elm, "events");
if (evt) {
elms.push(elm);
evTypes++;
attrs = ""
jQuery.each(evt, function(ky, vl) {
evCounter++;
attrs += ky + "-" + vl.length + " ";
});
jQuery(elm).attr(attrName, attrs);
}
});
console.clear();
console.info("There are " + evTypes + " diffrent types of events as a total of " + evCounter + " event, are attached to " + elmCounter + " elements.");
console.info("You will find a new attribute called '" + attrName + "' over the dom elements that have a jquery event attached" + '\n');
console.groupCollapsed();
jQuery.each(elms, function() {
console.log(this);
});
console.groupEnd();
return "▲ open group to see elements";
} else {
console.error("Ops, jQuery not detected");
}
return "Done!";
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment