Tracing jQuery trigger events
We will see how to modify the trigger event of jQuery so we can see everytime there is an event triggered, this is really usefull if you need debuging
I’ve had to see what trigger events have been fired when I was using jQuery, or to see if the trigger events I’ve done were working for a project.
So I had to modify the trigger event, but to also keep the functionality of jQuery the same so the following command gave me the stuff I needed to modify the trigger event.
Just write the following in developer tools of Chrome
$.fn.trigger
function ( type, data ) {
return this.each(function() {
jQuery.event.trigger( type, data, this );
});
}
So you modify this to the following, and now every-time there is a trigger event from jQuery you will be notified in the console.
$.fn.trigger = function ( type, data ) {
return this.each(function() {
console.log("trigger", type, data, this);
jQuery.event.trigger( type, data, this );
});
};