Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery bind all events on object [duplicate]

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?

like image 871
Harry Avatar asked Jul 05 '11 01:07

Harry


People also ask

How to bind events to an element in jQuery?

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.

What is the use of bind in jQuery?

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.

How do I remove a bind event from an event handler?

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.

What is the difference between bind () and on () methods in JavaScript?

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.


1 Answers

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.

like image 159
Kevin Stricker Avatar answered Sep 30 '22 17:09

Kevin Stricker