I'm trying to capture all DOM events on a page. This is the source code I've come up with to do so. It requires jQuery. Is there a better implementation out there? See any problems with my implementation?
// required jQuery
$('*').each(function () {
var ignore = [
'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave'
];
for (var key in this) {
if (key.substring(0, 2) === 'on') {
$(this).on(key.substr(2), function (event) {
var eventName = event.type,
tag = this.tagName.toLowerCase(),
id = this.id ? ('#' + this.id) : '';
if (ignore.indexOf(eventName) === -1) {
console.log(tag + id + ' ' + eventName);
}
});
}
}
});