Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to chain multiple events with one function in jQuery [duplicate]

Tags:

jquery

Possible Duplicate:
Jquery event chaining

Traditionally we may write:

    $("selector").click(function () {

    });

but is it possible to chain events, something like so:

    $("selector").click,keyup,keydown(function () {

    });

I'm aware of the fact that I could write a function and reference that function in three seperate handlers, but this would be cleaner.

like image 791
The Muffin Man Avatar asked Jan 28 '26 16:01

The Muffin Man


1 Answers

Use .bind()

$("selector").bind("keyup keydown click", function () {

});

For jQuery 1.7 and later, using the new API .on() is more preferred

$("selector").on("keyup keydown click", function () {

});
like image 136
Quincy Avatar answered Jan 31 '26 09:01

Quincy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!