5

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?

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.