How do you log all events fired by an element in jQuery?
I'd like to see all the events fired by an input field as a user interacts with it. This includes stuff like:
- Clicking on it.
- Clicking off it.
- Tabbing into it.
- Tabbing away from it.
- Ctrl+C and Ctrl+V on the keyboard.
- Right click -> Paste.
- Right click -> Cut.
- Right click -> Copy.
- Dragging and dropping text from another application.
- Modifying it with Javascript.
- Modifying it with a debug tool, like Firebug.
I'd like to display it using console.log
. Is this possible in Javascript/jQuery, and if so, how do I do it?
I have no idea why no-one uses this... (maybe because it's only a webkit thing)
Open console:
monitorEvents(document.body); // logs all events on the body
monitorEvents(document.body, 'mouse'); // logs mouse events on the body
monitorEvents(document.body.querySelectorAll('input')); // logs all events on inputs
$(element).on("click mousedown mouseup focus blur keydown change",function(e){
console.log(e);
});
That will get you a lot (but not all) of the information on if an event is fired... other than manually coding it like this, I can't think of any other way to do that.