title: How to fix "Uncaught TypeError: Cannot call method 'appendChild' of null"
body: <p>I am attempting to grab text from a HTML text area, and call the create() method when a 'Submit' button is pressed. The method is trying to use the message from the text area, and post that to its own p tag with class, and post a date stamp in its own p tag, and its own class.</p>
  
  <p>These will both be in the div 'comments'. The error I am getting (using developer tools in Chrome), is</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot call method 'appendChild' of null.</p>
  </blockquote>
  
  <p>This is aimed at "cmt.appendChild(divTag);". I am very new to Javascript, and this is just practise for me to increase my skills. All help is greatly appreciated!</p>
  
  <pre><code>var cmt = document.getElementById('comments');
  
  function create() {
  
      var username = 'User',
          message = document.getElementById("textBox").value,
          divTag = document.createElement('div'),
          p1 = document.createElement('p'),
          p2 = document.createElement('p');
  
      divTag.className = 'comment';
  
      p1.className = 'date';
      p1.innerHTML = new Date();
      divTag.appendChild(p1);
  
      p2.className = 'message';
      p2.innerHTML = username + ': ' +message;
      divTag.appendChild(p2);
  
      cmt.appendChild(divTag);
  }
  </code></pre>