Skip to content

Instantly share code, notes, and snippets.

@MohamedAlaa
Forked from zkareemz/jquery-attached-events
Last active February 5, 2025 02:06
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!";
})();
@bishopsfrighten
Copy link

This snippet of code adds events with data attributes attached to display comprehensive information and verifies and lists the jQuery events that are connected to DOM elements. Sprunki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment