title: addEventListener for an element that is inside of a form
body: <p>I have a simple form where I want to input something and store it. The addEventListener() method will not work when the button is inside of the form. Here is the code, html first, then JavaScript</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
          &lt;form&gt;
              &lt;h1&gt;Enter words to display &lt;/h1&gt;
              &lt;fieldset&gt;
                  &lt;input type="text" id="wordName" name="wordName"&gt;
              &lt;/fieldset&gt;
              &lt;button id="addWord"&gt;Add word&lt;/button&gt;
          &lt;/form&gt;
          &lt;script type="text/javascript" src="ch2_ex2.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>var wordInput = document.getElementById("wordName");
  var addWord = document.getElementById("addWord");
  
  addWord.addEventListener("click", fillArray);
  
  function fillArray() {
      console.log("do something");
  }
  </code></pre>
  
  <p>I find that the fillArray() method isnt being called. Why is this? I works when I put the button right below the <code>&lt;body&gt;</code> , but not from within the <code>&lt;form&gt;</code></p>