Javascript JQuery Document Event Lister

Submitted by code_admin on Mon, 07/23/2018 - 09:28

Run this code in repl to list events registered against the document in a human readable form


console.log("cur\ttype\tnamespace\tselector\tNum Match");
for (var cur=0;cur<jQuery._data( document, "events" ).click.length;cur++) {
var num_mat = $(jQuery._data( document, "events" ).click[cur].selector).size();
console.log(cur + "\t" + jQuery._data( document, "events" ).click[cur].type + "\t" + jQuery._data( document, "events" ).click[cur].namespace + "\t" + jQuery._data( document, "events" ).click[cur].selector + "\t" + num_mat);
}

Fund out which selectors match a particular element

set your element to test


var eleToTest = $("a[href$='#tab_inbound_pendingconnection_auth']")


console.log("Searching for events that match " + eleToTest[0]);
for (var cur=0;cur<jQuery._data( document, "events" ).click.length;cur++) {
var mat = $(jQuery._data( document, "events" ).click[cur].selector);
//console.log(mat.size() + " elements match event " + cur + " (NS:" + jQuery._data( document, "events" ).click[cur].namespace + "))");
for (var curele=0;curele<mat.size();curele++) {
//console.log(mat[curele]);
if (mat[curele]==eleToTest[0]) {
console.log("Event " + cur + " matches:");
console.log(jQuery._data( document, "events" ).click[cur]);
}
}
}

RJM Article Type
Quick Reference