Can I drain selectors with jQuery?

I know that "selectors" is the wrong term, but I can't remember it: P

I have this script:

$(function() {
   //checkbox
   $("#checkbox2, .akslabel").click(function(){
    $("#scrollwrap").toggleClass('highlight');
   });
});

Is it possible to add such selectors? Or should I rewrite it for everyone?

Thank!

+3
source share
3 answers

You can use as many selectors as you want in combination with ,( multiple selector ) and assign the same anonymous function to them all that your example does.

There is nothing wrong with that; it is cleaner / more concise code.

So can you drain the selectors? Yes, think of them as waffles, delicious waffles with bacon.

+5

, /id/etcetera.

, "akslabel", , "asklabel"...?

+2

This is normal, it is even better than splitting. Why duplicate code?

0
source

Source: https://habr.com/ru/post/1770292/


All Articles