Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide all divs with JavaScript?

I am wondering how I can hide all divs on the page only using JavaScript, I cannot use jQuery. Is there a way to do this without using the arrays that comes with document.getElementByTag? Or if there is not, could you show me how to hide all?

like image 863
eatonphil Avatar asked Aug 28 '12 21:08

eatonphil


1 Answers

Use getElementsByTagName() to get a list of all div elements, and then set their CSS display property to none:

var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
  divs[i].style.display = 'none';        
}
<div>sads</div>
<div>sads</div>
<span>not a div</span>
like image 120
João Silva Avatar answered Sep 20 '22 09:09

João Silva