title: JavaScript for loop undefined
body: <p>I wanted to make a couple of squares. When you press on one of them the square would disappear.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var square = document.querySelectorAll(".square");
  
  for (var i = 0; i &lt; square.length; i++) {
    square[i].addEventListener("click", function() {
      square.style.display = "none";
    })
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.square {
    background: red;
    height: 100px;
    width: 100px;
    margin-top: 20px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="square"&gt;&lt;/div&gt;
  &lt;div class="square"&gt;&lt;/div&gt;
  &lt;div class="square"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>For some reason console says <code>&quot;TypeError: square.style is undefined&quot;</code>...</p>