Home > OS >  Close responsive menu on clicking a <li>
Close responsive menu on clicking a <li>

Time:01-18

i just tried to do a JS which is closing my menu when i press a "

  • " button but it doesn't work, there is my html code.

    <input  type="button" value="Contacteaza-ma"/>
        <button id="but-menu"  onclick="openMenu()">
            <i ></i>
        </button>
        <div id="mobile-nav" >
            <buttton onclick="closeMenu()" ><i ></i></buttton>
            <div >
                <img  src="images/home-image.png"/>
                <p >Cristi Popescu</p>
            </div>
            <nav >
                <ul style="list-style-type:none;" >
                    <li><a  href="#about">DESPRE
                        MINE</a></li>
                    <li><a  href="#exp">EXPERIENTA</a></li>
                    <li><a  href="#edu">EDUCATIE</a></li>
                    <li><a  href="#apt">APTITUDINI</a></li>
                    <li><a  href="#ctc">CONTACT</a></li>
                </ul>
            </nav>
    

    and this is my JS:

    $( '.mobile-navigation__navigation-list li a' ).on("click", function(){
      $('closeMenu()').click();
    });
    
    

    What should i change? Thank you very much.

  • CodePudding user response:

    You can use the attribute onclick on the li element.

    Example:

    <ul>
      <li onclick="closeMenu()">Close menu</li>
    </ul>
    
    <script>
      function closeMenu() {
        //Close Menu
      }
    </script>
    
    •  Tags:  
    • Related