Hamburger menu automatically closing on wordpress

I have a problem with hamburger menu. After i click on a menu. it cant closing automatically.
All of the menus is working, except the automatically function

Can somebody help in this?

	var responsiveMenu = function() {
        var menuType = 'desktop';

        $(window).on('load resize', function() {
            var currMenuType = 'desktop';

            if ( matchMedia( 'only screen and (max-width: 991px)' ).matches ) {
                currMenuType = 'mobile';
            }

            if ( currMenuType !== menuType ) {
                menuType = currMenuType;

                if ( currMenuType === 'mobile' ) {
                    var $mobileMenu = $('#mainnav').attr('id', 'mainnav-mobi').hide();
                    var hasChildMenu = $('#mainnav-mobi').find('li:has(ul)');

                    $('#header').find('.header-wrap').after($mobileMenu);
                    hasChildMenu.children('ul').hide();
                    hasChildMenu.children('a').after('<span class="btn-submenu"></span>');
                    $('.btn-menu').removeClass('active');
                } else {
                   	var $desktopMenu = $('#mainnav-mobi').attr('id', 'mainnav').removeAttr('style');
				   	$desktopMenu.find('.sub-menu').removeAttr('style');
				   	$('#header').find('.col-md-10').after($desktopMenu);
				   	$('.btn-submenu').remove();
                }
            }
        });

        $('.btn-menu').on('click', function() {
            $('#mainnav-mobi').slideToggle(300);
            $(this).toggleClass('active');
        });

        $(document).on('click', '#mainnav-mobi li .btn-submenu', function(e) {
            $(this).toggleClass('active').next('ul').slideToggle(300);
            e.stopImmediatePropagation()
        });
    }

Read more here: Hamburger menu automatically closing on wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *