Catching more than one element with JQuery / JavaScript

3

Good morning!

Would you like me to get more than one element with JQuery?

For example, I'm doing this in my code:

if (!is992()) {
        $j('.filters .title--sm').click(function(){
        $j('.filters__list').slideToggle(50);
        $j('.filters__filtered').slideToggle(50);
        $j('.filters .title').toggleClass('active'); 
    });
}

I wanted to optimize these two lines:

$j('.filters__list').slideToggle(50);
$j('.filters__filtered').slideToggle(50);

Would you like me to take both classes and use it in single lines? For example:

$j('.filters__list', '.filters__filtered').slideToggle(50);

So I know you do not, but I wanted to know if there's something I can use.

Thank you!

    
asked by anonymous 13.10.2017 / 13:47

1 answer

4

You can use the comma to concatenate selectors in CSS. You were close, it would look like this:

$j('.filters__list, .filters__filtered').slideToggle(50);

If you have many classes to join you might want to give a common class to all those elements.

    
13.10.2017 / 13:48