Show and Hide elements on click with JavaScript

<style>
#snippet {
  width: 100%;
  padding: 50px 0;
  text-align: center;
  background-color: lightblue;
  margin-top: 20px;
}
</style>
<script>
function F1()
{
  var x = document.getElementById("snippet");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>
<button onclick="F1()"> <b>Step 1</b> </button>
  <div id="snippet" style="display: none;">
    <p> text </p>
  </div>

+1

Leave a Reply