Reputation: 9147
I have this code:
$("#leftbutton").click(function(e){
/// do xyz
});
$("#rightbutton").click(function(e){
/// do xyz (same thing)
});
How do I combine them so that if you click #leftbutton or #rightbutton it does xyz?
Something like this:
$("#leftbutton OR #rightbutton").click(function(e){
/// do xyz
});
Upvotes: 3
Views: 152
Reputation: 723538
Use the comma, also known in the jQuery docs as the multiple selector:
$("#leftbutton, #rightbutton").click(function(e){
/// do xyz
});
Upvotes: 7
Reputation: 17960
Just do:
$("#leftbutton, #rightbutton").click(function(e){
...
});
Upvotes: 1
Reputation: 22438
Just like CSS selectors, you could use the comma
$("#leftbutton, #rightbutton").click(function(e){
/// do xyz
});
Upvotes: 1