title: Javascript, add event listener to all buttons
body: <p>I am attempting to add event listeners to all of the buttons in an HTML document. When a button is pressed I'd like to display a simple alert. 
  My code, which isn't working at the moment, follows: </p>
  
  <pre><code>var bns = document.getElementsByTagName("button");
  
  function addtoev() {
    for (i = 0; i &lt; bns.length; i++) {
      bns[i].addEventListener("click", function() {
          alert("you clicked"); 
      });
     }
  }
  </code></pre>
  
  <p>It definitely works as such in JSFiddle by calling the method or eliminating the function line, but it's still not executing in Chrome (popups are not blocked). I post my HTML, is it possible that buttons nested in a table need to be referenced differently than buttons alone?</p>
  
  <pre><code>  &lt;tr&gt;
    &lt;td&gt;John&lt;/td&gt;
    &lt;td&gt;Doe&lt;/td&gt;
    &lt;td&gt;john@doe.us&lt;/td&gt;
     &lt;td&gt;&lt;button class="btn btn-default"&gt;X&lt;/button&gt;&lt;/td&gt;
    &lt;/tr&gt; 
  </code></pre>