title: Why can't I make "onclick" event handler in my javascript code?
body: <p>It works when I put the "onclick" handler as an attribute. Like</p>
  
  <pre><code>&lt;div class="myDiv" onclick="window.location='http://www.google.com/'"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>But it doesn't work when I do it like</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      ... Around here has "title","meta" and "css link", then ...
      &lt;script src="myEvent.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      ... Any thing here ...
      &lt;div class="myDiv"&gt;&lt;/div&gt;
      ... Any thing here ...
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And "myEvent.js" looks like</p>
  
  <pre><code>var myDiv = document.getElementsByClassName("myDiv");
  myDiv.onclick = function(){
    window.location = "http://www.google.com/
  };
  </code></pre>
  
  <p><strong>Thank you!</strong></p>