Hide elements in an array | JQuery

Is it possible to hide elements in an array, for example.

var elements = ['.div-1', '.div-3']; 

With structure:

 <div id="wrap"> <div class="div-1"></div> <div class="div-2"></div> <div class="div-3"></div> </div> 

So, div-2 should remain visible, and elements in the array will be hidden by fadeOut . Is it possible?

+4
source share
1 answer

You can use this array as a selector using .join() , for example:

 $(elements.join(', ')).fadeOut(); 

You can check it out here . By calling .join(', ') , you use a multiple selector , turning it into the string ".div-1, .div-3" and calling .fadeOut() for these elements.

+15
source

All Articles