title: addEventListener() to non-existent elements?
body: <p>I have attached a <code>click</code> event listener on an element like:</p>
  <pre><code>document.querySelector('.class-name').addEventListener('click', function () {
                      
  });
  </code></pre>
  <p>The element may or may not get generated from the server-side.</p>
  <p>So, if the server generates the element then all works fine but if not then I get an error like:</p>
  <p><code>Cannot read property 'addEventListener' of null</code></p>
  <p>I know why this happens, but I want to know whether there is a better way of attaching event listeners to elements that won't generate such errors?</p>