Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  1. Clicking on it.
  2. Clicking off it.
  3. Tabbing into it.
  4. Tabbing away from it.
  5. Ctrl+C and Ctrl+V on the keyboard.
  6. Right click -> Paste.
  7. Right click -> Cut.
  8. Right click -> Copy.
  9. Dragging and dropping text from another application.
  10. Modifying it with Javascript.
  11. 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?

like image 729
Daniel T. Avatar asked Sep 16 '11 02:09

Daniel T.


People also ask

How do you find out which Javascript Events fired?

Open Google Chrome and press F12 to open Dev Tools. Go to Event Listener Breakpoints, on the right: Click on the events and interact with the target element.

Can I console log in jQuery?

jQuery and console. log are unrelated entities, although useful when used together. If you use a browser's built-in dev tools, console. log will log information about the object being passed to the log function.

What is event method in jQuery?

Event methods trigger or attach a function to an event handler for the selected elements. The following table lists all the jQuery methods used to handle events. Method / Property.


2 Answers

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 
like image 143
sidonaldson Avatar answered Oct 29 '22 19:10

sidonaldson


$(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.

like image 24
Joseph Marikle Avatar answered Oct 29 '22 18:10

Joseph Marikle