mmenu.js - Use Dynamic DOM Elements for Search

685 views Asked by At

I really love the mmenu.js plugin. It's so slick and has a wealth of extremely helpful features.

I'm having a small problem with the search function, though. When I add any elements to the mmenu with javascript, they're unavailable for live-search. Is there any way to refresh the mmenu or ensure the the search function is looking through the most recent version of the DOM and not just the elements that were present upon initialization?

Thanks

Menu Markup

<nav id="my-menu">
    <ul>
        <li class="Label">Menu</li>
        <li><a href="/profile">Profile</a></li>
        <li><a href="/settings">Settings</a></li>
        <li><a href="/reports">Reports</a></li>
        <li><a href="/help">Help</a></li>
        <li><a href="/sign-out">Sign-Out</a></li>
    </ul>
</nav>

mmenu.js Startup

$("#my-menu").mmenu({
    searchfield: {
        add: true,
        search: true
    }
});

Add Item to Menu

$("#my-menu ul").append('<li><a href="/blog">Blog</a></li>');

In this example, the newly added "Blog" link doesn't react as a part of the search function.

0

There are 0 answers