I'm building my website based on Wordpress and have added a mobile menu. Now I'm hanging on the problem the submenu does not collapse when I click on the menu item.
The regular name of the submenu in Wordpress is .sub-menu, when there are more sub-menu's the menu collapse when I click on the menu item which has the submenu but all the sub-menu's collapse while I only want the one which is clicked to be collapsed.
Read about the (this) function but can't get it to work.
Any suggestions of what I'm doing wrong?
My default code which makes every submenu visible when click on menu item:
(function($){
jQuery(document).ready(function() {
jQuery('#mobilenav .menu-item-has-children').click(function(){
jQuery('#mobilenav .sub-menu').toggleClass('openup1');
});
});
})(jQuery);
The code I have made but which is not working:
(function($){
jQuery(document).ready(function() {
jQuery('#mobilenav .menu-item-has-children').click(function(){
jQuery(this).closest('#mobilenav .sub-menu').toggleClass('openup1');
});
});
})(jQuery);