Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Selectors with jQuery

Can I select two elements with Jquery at the one time?

For example I tried this but it only selected the first element:

$('.loginStaff' || '.loginClient').click(function(){
    $('.login_form').toggle();
});

I also tried but this only selected the last element:

$('.loginStaff' && '.loginClient').click(function(){
    $('.login_form').toggle();
});

Thanks!!! Global

like image 345
Globalz Avatar asked Sep 13 '26 05:09

Globalz


1 Answers

Just use a comma to separate your selectors and it will match the combined results of all:

$('.loginStaff,.loginClient').click(function(){
  //..
});

More info:

  • Selectors/multiple
like image 62
Christian C. Salvadó Avatar answered Sep 15 '26 19:09

Christian C. Salvadó



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!