title: Javascript: AppendChild
body: <p>I was learning about <code>appendChild</code> and have so far come up with this code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var blah = "Blah!";
  var t = document.createElement("table"),
    tb = document.createElement("tbody"),
    tr = document.createElement("tr"),
    td = document.createElement("td");
  
  t.style.width = "100%";
  t.style.borderCollapse = 'collapse';
  
  td.appendChild(document.createTextNode(blah));
  
  // note the reverse order of adding child        
  tr.appendChild(td);
  tb.appendChild(tr);
  t.appendChild(tb);
  
  document.getElementById("theBlah").appendChild(t);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="theBlah"&gt;d&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>But that gives me an error saying <code>Uncaught TypeError: Cannot call method 'appendChild' of null</code>. What am I doing wrong?</p>