title: how to print javascript variable to html tags
body: <p>I have this code</p>
  
  <pre><code>&lt;script language="javascript"&gt;var str = "test"; &lt;/script&gt;
  </code></pre>
  
  <p>I want to print it to a h2 tag in my html</p>
  
  <pre><code>&lt;h2 id="header2"&gt; &lt;/h2&gt;
  </code></pre>
  
  <p>I have tried using <code>document.write (str)</code>;</p>
  
  <p>I have also tried <code>document.getElementById("header2").innerHTML = str;</code></p>
  
  <p>but nothing worked</p>