title: javascript - call function when button is clicked
body: <p>Can someone show me what I am doing wrong here?</p>
  
  <p>I am trying to execute a function when a button is clicked.</p>
  
  <p><strong>The HTML:</strong></p>
  
  <pre><code>&lt;button id="btn1"&gt;Press me!&lt;/button&gt;
  &lt;input type="button" id="btn2" value="Press me!"/&gt;​
  </code></pre>
  
  <p><strong>The javascript:</strong></p>
  
  <pre><code>var btn1 = document.getElementById('btn1'),
      btn2 = document.getElementById('btn2');
  
  
  function do() {
      alert('Yay!');
  }
  btn1.onclick = do;
  btn2.onclick = do;​
  </code></pre>
  
  <p><a href="http://jsfiddle.net/Daniel_Hug/pFYUM" rel="nofollow">Here's a demo.</a> I'm not sure why it's not working. It's probobly something way to obvious for me to notice. :)</p>