简体   繁体   中英

Wordpress Menu - Show Sub-menu on Click

I would like to hide the submenus and show them after their parents get clicked. At the moment I'm using a snippet I found on here, which unfortunately doesn't hide the submenu when loading. So I'm basically looking for an inverted solution of this or something completely else :)

The site: https://webnew.dpg-gruppe.eu

The snippet:

 $(document).ready(function () { $('#navmenu > ul > li:has(ul)').addClass("has-sub"); $('#navmenu > ul > li > a').click(function () { var checkElement = $(this).next(); $('#navmenu li').removeClass('active'); $(this).closest('li').addClass('active'); if ((checkElement.is('ul')) && (checkElement.is(':visible'))) { $(this).closest('li').removeClass('active'); checkElement.slideUp('normal'); } if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#navmenu ul ul:visible').slideUp('normal'); checkElement.slideDown('normal'); } if (checkElement.is('ul')) { return false; } else { return true; } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

You can try to add this line

$('#navmenu ul.sub-menu').hide();

after $(document).ready(function () {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM