Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide elements that are in an array | jQuery

Tags:

arrays

jquery

Is it possible to hide elements that are in an array, e.g.

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

With a structure of:

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

So div-2 should stay visible, while the elements that are in the array would be hidden by fadeOut. Is this possible?

like image 349
MacMac Avatar asked Oct 04 '10 20:10

MacMac


1 Answers

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

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

You can test it out here. By calling .join(', ') you're using the multiple selector by turning it into the string ".div-1, .div-3" and calling .fadeOut() on those elements.

like image 181
Nick Craver Avatar answered Oct 14 '22 17:10

Nick Craver