Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change div style display none to block and vice versa with javascript

I’m working on a page description that has a "saiba mais" button that when I click the button it expands and hides the description.
How can I do this with javascript?

That’s my code:

<div class="members-description">
  <h4>
    Text here
  </h4>
  <div class="about" id="about" style="display: none">
    <p>
      Text here
    </p>
    <p>
      Text here
    </p>
    <p>
      Text here
    </p>
    <p>
      Text here
    </p>
  </div>
  <a class="btn">Saiba Mais</a>
</div>

I need that when I click on the button it expands the description and when I click again it hides the description.
There’s a gif with the result I need.
expected outcome

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks to whoever answers the question and sorry if I couldn’t express my problem correctly.

>Solution :

const aboutDiv = document.getElementById("about");
const btn = document.querySelector(".btn");

btn.addEventListener("click", () => {
  if (aboutDiv.style.display === "none") {
    aboutDiv.style.display = "block";
    btn.textContent = "Esconder";
  } else {
    aboutDiv.style.display = "none";
    btn.textContent = "Saiba Mais";
  }
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading