title: change background color with JavaScript
body: <p>I have a main div containing n * n divs which have either a black background or a white one.</p>
  
  <p>I want them to change their BGcolor by clicking on the main div.</p>
  
  <p>Here's my code (that doesn't work obviously).</p>
  
  <pre><code>    function invert(){
  
  
     var divs = document.getsElementsByTagName("div");
  
     for(i=0; i&lt;divs.length; i++){
            if(divs[i].style.backgroundColor=="black")
            {
              divs[i].style.backgroundColor="white";
            }
            else if (divs[i].style.backgroundColor=="white") 
            {
              divs[i].style.backgroundColor="black";
            }
  
  
  
     }
  
  }
  </code></pre>