Reputation: 46222
Is there a way to say on any event fire
$('#foo').bind('click', function() {
alert($(this).text());
});
I am trying to test a piece of code for a certain event and not going in there. Just want it to fire fore ANY event.
$('#foo').bind('ANY', function() {
alert($(this).text());
});
Upvotes: 3
Views: 285
Reputation: 2183
I don't think that is possible, but you can use Firebug to view all events that are bound to a page element.
Open up Firebug and then in the console write the following:
$("#foo").data("events");
That should display any event that is bound to the #foo element.
Upvotes: 0
Reputation: 94429
You can specify every event separated by spaces in the first argument of the bind function. This will bind to all events. To view all events covered by jquery visit the documentation.
Upvotes: 0
Reputation: 129792
There's no shorthand for listening to all events.
The closest thing you can get out of the box would be specifying them manually:
$('#foo').bind('blur change click dblclick focus focusin focusout hover keydown ...', function() {
alert($(this).text());
});
Note that plugins may fire their own events, perhaps namespaced. You can't listen to these events without knowing them and manually specifying them.
Upvotes: 2