@William, for this you need a common element among all mirror. For example look at the HTML below:
HTML
<div id="mirror30" data-mirror class="hidden" ></div>
<div id="mirror31" data-mirror ></div>
<div id="mirror32" data-mirror ></div>
<div id="mirror33" data-mirror ></div>
<div id="mirror34" data-mirror class="hidden" ></div>
<div id="add4mirror" data-mirror ></div>
CSS
.hidden { display: none; }
In the above case, all the mirror has the data-mirror property, so you can use it to select to all of them.
Since you only need visible ones, you can apply a filter :visible
$("[data-mirror]:visible").hide("slow");
var btHidden = $("#btHidden");
btHidden.click(function () {
var visibleMirror = $("[data-mirror]:visible");
visibleMirror.hide("slow");
});
.hidden { display: none; }
.container {
height: 120px;
}
.mirror {
float: left;
background-color: whitesmoke;
width: 100px;
height: 100px;
box-shadow: 0px 0px 10px black;
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div id="mirror30" data-mirror class="mirror hidden" ></div>
<div id="mirror31" data-mirror class="mirror" ></div>
<div id="mirror32" data-mirror class="mirror" ></div>
<div id="mirror33" data-mirror class="mirror" ></div>
<div id="mirror34" data-mirror class="mirror hidden" ></div>
<div id="add4mirror" data-mirror class="mirror" ></div>
</div>
<button id="btHidden" >Esconder Tudo</button>
You can do everything in one line:
$("#mirror31, #mirror32, #mirror33, #add4mirror").hide("slow");
– Oeslei
And there’s no way I won’t have to write them all?
– GGirotto
Adding classes to the elements is one of the most common uses. You can also leave a container out of the elements and hide only the cantainer. There are several ways to do this, depends on creativity...
– Oeslei
Renan and how do I hide the whole sequence? give an Hide in foo[]?
– GGirotto