title: Event handlers don't work in js
body: <p>Why do my event handlers not work in my javascript function.If it's the wrong way to access a button event handler inside a js function than how to do it correctly?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function cl(){
      var button = document.getElementById('but');
      button.onclick = function (){
          alert('this works');
      }
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;input type="button" value = "click" id = "but"&gt;
  &lt;/body&gt;
  </code></pre>