title: Dynamically create and print h1 tags through JavaScript
body: <p>I need to be able to create a function in JavaScript where all I need to do is type h1("hello") and it will print hello.</p>
  
  <p>I want to avoid this method:</p>
  
  <pre><code>function h1(text) {
      document.write('&lt;h1&gt;'+text+'&lt;/h1&gt;');
  }
  </code></pre>
  
  <p>This is what I have:</p>
  
  <pre><code>function h1(text) {
      var div = document.createElement('div');
      document.appendChild(div);
      var h1 = document.createElement('h1');
      div.appendChild(h1);
      h1.createTextNode(text);
  }
  </code></pre>