title: Error in appendchild
body: <p>I have the following very simple code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;script type="text/javascript" &gt;
  
      function showAlert(){
        alert("I am clicked");
      }
  
      function one(){
        var a1 = [1,2,3];
        for (var i=0;i&lt;a1.length;i++) {
          var p = document.createElement('p');
          p.innerHTML = a1[i];
          p.onclick = showAlert;
          document.body.appendChild(p);
        }
  
        console.log("I am called");
      }
  
      one();   
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am getting the following error:<code>Uncaught TypeError: Cannot read property 'appendChild' of null</code>. Can anybody tell me, where am I going wrong? I am testing in <code>Chrome</code>.</p>