title: How do I change the text of a heading with a javascript button?
body: <p>noob here.
  I want to make a variable out of some text, so that when I click it old text becomes new text.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;h1 id="id01"&gt;THis is the old text&lt;/h1&gt;
  
  &lt;p&gt;Click on "My Button" to display its value attribute.&lt;/p&gt;
  
  &lt;button id="myBtn" name="myname" value="myvalue" 
  onclick="alert(this.value)"&gt;My Button&lt;/button&gt;
  
  &lt;p&gt;Click on "Try it" to change the value attribute of "My Button".&lt;/p&gt;
  
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;p&gt;&lt;b&gt;Tip:&lt;/b&gt; Click on "My Button" before and after you have clicked on 
  "Try it".&lt;/p&gt;
  
  &lt;script&gt;
  function myFunction() {
      document.getElementById("myBtn").value = "newButtonValue";
      document.getElementById("id01").value = "this is the new text";
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the first example I use, but var = would be a better alternative.</p>