<div class="name"> 1 </div>
<div class="name"> 2 </div>
<div class="name2"> 3 </div>
<input type="button" onclick="a()" value="Hidde"/>
function a(){
var name = document.getElementsByClassName('name');
for(key in name) {
name[key].style.display="none";
}
<input type="button" onclick="hide()" value="Hide" />
function hide() {
for (let key of document.querySelectorAll('.name')) {
key.hidden = true;
}
}
key.hidden = !key.hidden;