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?
There is a nice generic way using the .data('events') collection:
This logs every event that has been already bound to the element by jQuery the moment this specific event gets fired. This code was pretty damn helpful for me many times.
Btw: If you want to see every possible event being fired on an object use firebug: just right click on the DOM element in html tab and check "Log Events". Every event then gets logged to the console (this is sometimes a bit annoying because it logs every mouse movement...).
https://github.com/robertleeplummerjr/wiretap.js
Just add this to the page and no other worries, will handle rest for you:
You can also use console.log('Input event:' + e.type) to make it easier.
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.
I know the answer has already been accepted to this, but I think there might be a slightly more reliable way where you don't necessarily have to know the name of the event beforehand. This only works for native events though as far as I know, not custom ones that have been created by plugins. I opted to omit the use of jQuery to simplify things a little.
I hope this helps anyone who reads this.
EDIT
So I saw another question here that was similar, so another suggestion would be to do the following:
STEP 1: Check the
events
for anHTML element
on thedeveloper console
:STEP 2: Listen to the
events
we want to capture:Good Luck...