skip to Main Content

I have a heading to list the items
List Name
List 1
List 2
List 3
List 4

but i need to display the listed items after click the "List Name". The Listed Items are to be hidden until click the "List Name". What is the coding for it in HTML

Need Coding for HTML

2

Answers


  1. it’s works for me :

      document.getElementById("list-name").addEventListener("click", function() {
        var listItems = document.getElementById("list-items");
        if (listItems.style.display === "none") {
          listItems.style.display = "block";
        } else {
          listItems.style.display = "none";
        }
      });
    <button id="list-name">List Name</button>
    <ul id="list-items" style="display:none;">
      <li>List 1</li>
      <li>List 2</li>
      <li>List 3</li>
      <li>List 4</li>
    </ul>
    Login or Signup to reply.
  2. You can use jquery or javascript for this.

    <script>
    $(document).ready(function(){
      $(".list-name").click(function(){
        $(".list").toggle();
      });
    });
    </script>
    
    <ul class="list">
       <li>A</li>
       <li>B</li>
       <li>C</li>
       <li>D</li>
    </ul>
    
    <a href="" class="list-name">List Name</a>
    

    You can use this script to hide and show the list item on click.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search