How can i check which event called my function on Javascript with Jquery?
Like i have:
var mycall= function() {
alert('Which Witch is Which?');
}
$(window).load(mycall);
$(window).resize(mycall);
I understand that i could pass a parameter to the function, still i'm interested in a way to do this without passing any parameters.
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. If the event will fire, then you will get a breakpoint in the debugger.
jQuery trigger() Method The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.
Answer: Use the event. target Property You can use the event. target property to get the ID of the element that fired an event in jQuery. This property always refers to the element that triggered the event.
Use the type
property in the event
object:
var mycall = function(e) {
alert(e.type);
};
Add an event to the function args and then event.type
will give tell which event is triggered. See below,
var mycall= function(e) {
alert(e.type);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With