开发者

Hide elements that are in an array | jQuery

开发者 https://www.devze.com 2023-01-18 21:46 出处:网络
Is it possible to hide elements that are in an array, e.g. var elements = [\'.div-1\', \'.div-3\']; With a structure of:

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">&开发者_JAVA百科lt;/div>
</div>

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号