Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

html conditional display

<body>
  <div id="display">This div will stay visible</div>
  <div id="conditional">This div will appear if conditional is true</div>
  <button onclick="toggle_display()">Toggle conditional display</button>
  
  <script>
    const conditional_div = document.getElementById('conditional');
    let condition = true;
    const toggle_display = function() {
      if (condition) {
        conditional_div.style.display = "none";
        condition = false;
        return
      };
                    //can be: flex, grid, etc...
      conditional_div.style.display = "block";
      condition = true;
      return
    };
  </script>
</body>
 
PREVIOUS NEXT
Tagged: #html #conditional #display
ADD COMMENT
Topic
Name
6+5 =