2

I'm trying to figure out a way to trigger a submenu from outside the mmenu structure.

Opening a submenu with a link directly refering to the mmenu id, doesn't work:

<div class="content">
   <a href="#mm-2">Open submenu from here</a>
</div>

http://jsfiddle.net/9FdXv/40/

Roddeh
  • 207
  • 1
  • 6
  • 19

2 Answers2

1

Add the id external or whatever you like to your external anchor. Also add an id to the ul constituing your "80% werken" menu. (In this example I used 80_sub). Now add the following to your js script:

$('#external').click(function(ev) {
    ev.preventDefault(); //Avoid mmenu to get the click and close
    var api = $("#my-menu").data( "mmenu" );
    api.openPanel( $("#80_sub") );
});

We are manually manipulating the menu using the API.

Edit: Working example based on your fiddle.

SystemGlitch
  • 2,150
  • 12
  • 27
  • thanks @GSystemGlitch works great, but the content div is dynamically loaded, if I add the anchor in a the content page, your solution doesn't work. How should I get that to work? – Roddeh Apr 27 '18 at 15:30
  • See [this question](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – SystemGlitch Apr 27 '18 at 20:49
1

Check This fiddle for open a menu dynamically.I've user trigger event of the menu.

You can add id of the menu as data-href in a tag like the following

<a href="javascript:void(0);" data-href="#mm-2" class="open-dynamic"><span>Open the submenu "80% werken" from here</span></a>

You can generate all menu external link by adding different id in the a tag.

And the following script will work for open a menu.

 $(document).on("click", ".open-dynamic", function () {                    
                    $(document).find("[href='" + $(this).attr("data-href") + "']").trigger("click");                   
            });

Check This fiddle

Jaydip Shingala
  • 429
  • 2
  • 11
  • 18