Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
List all event listeners in a document
console.table((function listAllEventListeners() {
const allElements ='*'));
allElements.push(document); // we also want document events
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
let elements = [];
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];
for (let j = 0; j < types.length; j++) {
if (typeof currentElement[types[j]] === 'function') {
"node": currentElement,
"type": types[j],
"func": currentElement[types[j]].toString(),
return elements.sort(function(a,b) {
return a.type.localeCompare(b.type);

This comment has been minimized.


This comment has been minimized.

Copy link

@thepeoplesbourgeois thepeoplesbourgeois commented Nov 5, 2019

I went ahead and made my own implementation. Mutationless, for-free, probably a little slower:

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