menu

arrow_back How to start menu? Uncaught TypeError: Cannot read property 'open' of undefined?

by
0 votes
<nav id="my-panel">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about/">About us</a>
<ul>
<li><a href="/about/history/">History</a></li>
<li><a href="/about/team/">The team</a></li>
<li><a href="/about/address/">Our address</a></li>
</ul>
</li>
<li><a href="/contact/">Contact</a></li>
</ul>
</nav>
<button id="toggler" class="hamburger" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>


$(document).ready(function() {
$("#my-menu").mmenu();
var API = $("#my-menu").data("mmenu");

$("#toggler").click(function() {
API.open();
});
});


выбивает ошибку
Uncaught TypeError: Cannot read property 'open' of undefined
at HTMLButtonElement. (scripts.min.js:1)
at HTMLButtonElement.dispatch (jquery.min.js:3)
at HTMLButtonElement.q.handle (jquery.min.js:3)

Памагите что делать ?

1 comment

When you refer to a variable API, you pass it ordinary text. Course text there is no such properties/methods as open, and swears.

You should carefully read, such as on Habre article contains an example: https://habrahabr.ru/sandbox/106740/

In your case you can specify this: var API = $("#my-menu").mmenu().data("mmenu");

1 Answer

by
0 votes
And anything that you have or where no id my-menu ?