JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" id="test">test</a>
JavaScript
$(function() {
i = 0;
window.events = [];
$('a').each(function() { //give each anchor an id using data-id, and save the length of click events in window.events array
$(this).attr('data-id', i);
window.events[i] = $._data($(this)[0], 'events') == undefined ? 0 : $._data($(this)[0], 'events')['click'].length; //if no events are bound it'll return undefined, so check for it and set length to 0 if that's the case
i++;
});
window.setInterval(function() { //check every 500ms to see if that length changed
checkEvents();
}, 500);
window.checkEvents = function() {
$('a').each(function() {
index = $(this).attr('data-id');
if ($._data($(this)[0], 'events') != undefined) {
if (window.events[index] != $._data($(this)[0], 'events')['click'].length) {
//fires when length of click events on any anchor has changed
console.log('event bound on anchor #' + index);
}
}
});
}
});