CLOSE-OPEN SCRIPT

by Nevear

HTML

<p id="toggle">Hide THIRD</p>
  <div id="third">This is the THIRD </div>

CSS

.third{color:red;}

JavaScript

const targetDiv = document.getElementById('third');
const btn = document.getElementById("toggle");
btn.onclick = function () {
  if (targetDiv.style.display !== "none") {
    targetDiv.style.display = "none";
  } else {
    targetDiv.style.display = "block";
  }
};