Toggle a simple navigation in Javascript

前端 未结 3 783
时光取名叫无心
时光取名叫无心 2021-01-28 05:24

I want to have a very simple navigation menu. It has to be clickable. So when using this code

3条回答
  •  自闭症患者
    2021-01-28 06:08

    It would be much easier to make a CSS class that hides the elements, which is then toggled by JS. This answer doesn't require jQuery

    function toggleMenu(){
        document.getElementById('navContent').classList.toggle("hidden")
    }
    #navContainer {
        position: relative;
        display: inline-block;
    }
    
    #navContent button {
        display: block;
    }
    
    .hidden {
        display: none;
    }

提交回复
热议问题