title: changing the content of a div
body: <p>I would like to change the content of a div. I have three divs:</p>
  <pre><code> &lt;div
        class=&quot;box1&quot;
        style=&quot;height: 200px; width: 200px; background-color: red&quot;
      &gt;
        A
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div
        class=&quot;box2&quot;
        style=&quot;height: 200px; width: 200px; background-color: blue&quot;
      &gt;
        &lt;label for=&quot;&quot;&gt;tex&lt;/label&gt;
        &lt;input type=&quot;text&quot; /&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div
        class=&quot;box3&quot;
        style=&quot;height: 200px; width: 200px; background-color: yellow&quot;
      &gt;
        C
      &lt;/div&gt;
  </code></pre>
  <p>when the page is ready the 2 and 3rd box displays none:</p>
  <pre><code>function hideElementBoxOnLoad() {
    let box1 = document.querySelector(&quot;.box1&quot;);
    let box2 = document.querySelector(&quot;.box2&quot;);
    let box3 = document.querySelector(&quot;.box3&quot;);
  
    box2.style.display = &quot;none&quot;;
    box3.style.display = &quot;none&quot;;
  }
  
  $(document).ready(hideElementBoxOnLoad);
  </code></pre>
  <p>I want a click that toggles the content of box2 and box3 into box1 and then back to box1 content:</p>
  <pre><code>function changeContent() {
    let chang = true;
    let box1 = document.querySelector(&quot;.box1&quot;);
    let box2 = document.querySelector(&quot;.box2&quot;);
    let box3 = document.querySelector(&quot;.box3&quot;);
  
    let box2Content = box2.textContent;
    let box3Content = box3.textContent;
  
    if (chang) {
      box1.textContent = box2Content;
      chang = !chang;
      if ((box1.textContent === box2Content)) {
        box1.textContent = box3Content;
      }
    }
  }
  
  let btn = document.getElementById(&quot;btn&quot;);
  btn.addEventListener(&quot;click&quot;, changeContent);
  </code></pre>
  <p>So far it worked but it does not display the content of box2 only box3. what did i do wrong and what better way can i toggle with a boolean.</p>