Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help me with the "or" jquery selector?

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
});
like image 258
Dave Avatar asked Jan 26 '26 05:01

Dave


1 Answers

Use the comma, also known in the jQuery docs as the multiple selector:

$("#leftbutton, #rightbutton").click(function(e){
 /// do xyz
});
like image 129
BoltClock Avatar answered Jan 27 '26 19:01

BoltClock