4
I have the following array:
var elementos = [$("#elemento1"), $("#elemento2"), $("#elemento3")]
I need to create a function that "converts" this array into a jQuery instance, so I can use jQuery functions on all at once.
I tried that:
var elementos = [$("#elemento1"), $("#elemento2"), $("#elemento3")];
$(elementos).hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="elemento1">Elemento 1</p>
<p id="elemento2">Elemento 2</p>
<p id="elemento3">Elemento 3</p>
But I did not succeed, I know that the best would be to use each. But this is possible?
As you can see, I tried to use $(elements). But when I try to hide them, it won’t.
– Salomão Neto
@Salomãoneto you’re right. I was on the mobile and read wrong. I corrected and added examples.
– Sergio