Possible Duplicate:
How all events of dom element can be bind?
I have an object that gets events triggered against it.
How do I bind all the events and console.log the event name?
We have used their click (), mouseover (), mouseout () methods to bind events to any element and perform any action when the event occurs. The bind () method in jQuery attaches one or more event handlers for selected elements and specifies a function to run when the event occurs. The bind () method was deprecated in version 3.0.
jQuery bind () method The bind () method in jQuery attaches one or more event handlers for selected elements and specifies a function to run when the event occurs. The bind () method was deprecated in version 3.0. Use the on () method instead.
This function can be removed at a later time by calling: .unbind ( eventName, false ). The handler callback function can also take parameters. When the function is called, the event object will be passed to the first parameter.
Use the on () method instead. The bind () method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs. Required.
You can bind all the standard javascript events by including them in the bind call separated by spaces. The jQuery docs provide this list:
blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error
So, to bind the event for click, blur and focus:
$('#foo').bind('click blur focus', function(event) {
console.log(event.type);
});
If you're looking for custom events, you'll have to look at the API and bind those as well. There doesn't appear to be any way to bind on any event.
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