Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery mobile menu to close after i click a menu item

based on this demo: http://webdesignerwall.com/demo/mobile-nav/ this is my code.

<script type="text/javascript">
    jQuery(document).ready(function($){

        /* prepend menu icon */
        $('#nav-wrap').prepend('<div id="menu-icon"><img id="logo" src="<?php echo site_url(); ?>/wp-content/themes/blue-and-grey/images/mobileimages/hme_btn.png" /></div>');

        /* toggle nav */
        $("#menu-icon").on("click", function(){
            $("#nav").slideToggle();
            $(this).toggleClass("active");
        });

    });
    </script>

what i need is the menu to "close" after i click a menu item because it's a single page website, and i don't want it to stay opened after i clicked. how do i do that?

thank you so much!

like image 850
valerio0999 Avatar asked Oct 03 '22 18:10

valerio0999


1 Answers

Add an extra event to make it happen. You could trigger the click of #menu-icon when some menu item is clicked:

 $("#nav").on("click", "li", function () {
       $("#menu-icon").click();
       //or $("#nav").slideToggle();
 });

Demo : http://jsfiddle.net/hungerpain/RtMNj/2/

like image 126
krishwader Avatar answered Oct 13 '22 10:10

krishwader