Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple triggers for a jquery-click-event [duplicate]

Sorry for that simple question, but how do I add multiple triggers to a jquery-click-event?

I tried that one here

$("#trigger1","#trigger2").click(function() {
    //something
});

But that doesn't work. What is the correct syntax there?

like image 842
Daiaiai Avatar asked Oct 20 '25 22:10

Daiaiai


2 Answers

Should be like :

$("#trigger1, #trigger2").click(function() {
    //Put your logic here
});

Just remove the extra quotes.

Hope this helps.

like image 111
Zakaria Acharki Avatar answered Oct 23 '25 11:10

Zakaria Acharki


The reason why your code is not working is you are using a context selector. So what it is saying is: Find #trigger2 and inside of that look for #trigger1.

But what you want is to use a multiple selector.

$("#trigger1, #trigger2").click( ... )

Or I would just use a common class so you do not have to keep track of the ids

$(".commonClass").click( ... )
like image 39
epascarello Avatar answered Oct 23 '25 13:10

epascarello



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!