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?
Should be like :
$("#trigger1, #trigger2").click(function() {
//Put your logic here
});
Just remove the extra quotes.
Hope this helps.
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( ... )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With