Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
monitorEvents.js
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);
});
}
@SerkanSipahi

This comment has been minimized.

Copy link

commented Dec 26, 2017

ES6 Version with some optimizations (optional callback):

let monitorEvents = (el, callback) => {
  let eventCallback = callback || ((e) => console.log(e));
  let events = [];

  for(var i in el) {
    if(i.startsWith("on")) events.push(i.substr(2));
  }
  events.forEach(eventName => el.addEventListener(eventName, eventCallback)); 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.