Created
October 14, 2016 07:38
-
-
Save PaulKinlan/45de2fb55c1390d871b3a67f72ae730c to your computer and use it in GitHub Desktop.
monitorEvents.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function monitorEvents(element) { | |
var log = function(e) { console.log(e);}; | |
var events = []; | |
for(var i in element) { | |
if(i.startsWith("on")) events.push(i.substr(2)); | |
} | |
events.forEach(function(eventName) { | |
element.addEventListener(eventName, log); | |
}); | |
} |
This doesn't include events such as DOMContentLoaded.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The most common use is to monitor the document. The following snippet directly does just that:
The benefit of a function is to be able to monitor only part of the page (to reduce noise from unrelated areas), and to be able to unmonitor it without having to reload the page.
Below is a modified version that includes the missing
unmonitorEvents()
function to do exactly that.