1. PROMO Subscribe our All Access Pass @ 75% OFF & access all our 16+ premium Divi extensions: Divi Block Pro, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Solved Make parent menu item behave same as toggle to open submenu on mobile menu

Discussion in 'Free Divi Community Forum' started by Jonathan Lee, Feb 25, 2022.

  1. Jonathan Lee

    Jonathan Lee New Member

    Hello,

    As stated in the title, I would like for my parent items to expand their submenu when clicked, rather than just closing the menu (since the parent menu items aren't linked). I am using code from here: https://www.peeayecreative.com/how-to-collapse-divi-mobile-menu-submenus/ to create my mobile menu. They have included some code that is supposed to achieve what I want, and the code makes sense to me, but I can't seem to get it to work. Alternatively, if anyone knows a way to stop the menu from being closed after clicking a parent item that would be helpful as well.

    I appreciate any help or advice! My site url is located at: https://mypropainters.com/
     
    1. PRO MEMBER PERKS Divi Block Pro - 30+ premade custom header designs for you to choose from:View Demo
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    For this line of code:

    $('ul.et_mobile_menu li.menu-item-has-children .mobile-toggle, ul.et_mobile_menu li.page_item_has_children .mobile-toggle').click(function(event) {

    Try to replace it with the below & see if it works:

    $('ul.et_mobile_menu li.menu-item-has-children>a, ul.et_mobile_menu li.page_item_has_children>a').click(function(event) {
     
  3. Jonathan Lee

    Jonathan Lee New Member

    Thank you for the response! This does allow the submenu to be opened when clicked, but the menu still closes when the parent item is clicked. Is there any way to prevent the menu from being closed after clicking the parent item?
     
    1. PRO MEMBER PERKS Divi Ultimate Header Plugin - Custom Divi Builder header on desktop + default slide in / fullscreen menu on mobile:Learn More
  4. Divi.Help

    Divi.Help Administrator
    Staff Member

    I see that preventdefault is already added to the click function. Not sure why it didn't take effect.

    Perhaps you might want to try other solutions: https://www.elegantthemes.com/blog/...llapsing-nested-menu-with-divis-theme-builder
     
  5. Jonathan Lee

    Jonathan Lee New Member

    I figured out the solution by manually adding/removing the open/closed class. I replaced the preventdefault with this line of code:
    $('div.mobile_nav').removeClass('closed').addClass('opened');

    Thank you for your help.
     
    Marcoduv likes this.
    1. PRO MEMBER PERKS Divi Block Pro - 30+ premade custom header designs for you to choose from:View Demo
  6. Marcoduv

    Marcoduv New Member

    Hi,
    I have the same problem. Can you please post the full code of your java script.
    Regards,
    Marc