title: Unobtrusive Javascript onclick
body: <p>I was recently reading on Unobtrusive javascript and decided to give it a shot. Whether or not I decide to use this style is to be determined at a later time. This is just for my own curiosity and not for any time restricted project.</p>
  
  <p>Now, I was looking at example code and a lot of the examples seem to be using, what took me forever to discover, jQuery. They use a function like $('class-name').whatever(...);</p>
  
  <p>Well I rather like the look of $('class').function, so I tried to emulate it without using jQuery(as I don't know jQuery and don't care about it atm). I'm unable, however, to make this example work.</p>
  
  <p>Here is my jsFiddle: <a href="http://jsfiddle.net/dethnull/K3eAc/3/" rel="noreferrer">http://jsfiddle.net/dethnull/K3eAc/3/</a></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Unobtrusive Javascript test&lt;/title&gt;
  &lt;script&gt;
      function $(id) {
          return document.getElementById(id);
      }
  
      $('tester').onclick(function () {
          alert('Hello world');
      });
  &lt;/script&gt;
  &lt;style&gt;
      .styled {
          width: 200px;
          margin-left: auto;
          margin-right: auto;
          font-size: 2em;
      }
      a {
          cursor: pointer;
          color: blue;
      }
      a:hover {
          text-decoration: underline;
      }   
  &lt;/style&gt;
  &lt;/head&gt;
      &lt;body&gt;
          &lt;div class='styled'&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a id='tester'&gt;CLICK ME&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
  
           &lt;/div&gt; 
       &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I was expecting an alert box to pop up when you click on the link, but doesn't seem to happen. When checking the console in chrome it gives this message "Uncaught TypeError: Cannot call method 'onClick' of null"</p>
  
  <p>I'm not a javascript expert, so more than likely I'm doing something wrong. Any help is appreciated.</p>