var h = document.getElementsByClassName("homeDisplay"); for (var i = 0; i < h.length; i++) { if (!h[i].getElementsByClassName("overlay inShow")[0]) { h[i].style.display = "none"; } }