I am trying to refactor the menu navigation. I want to add it into a single html file. example: menu.html will contain :
<div class="menu-toggle" id="menuToggle">
<span></span>
</div>
other divs aswell
For each page I want to inject this html code. (to increase code reuse). using other html page:
<div id='menu=left'></div>
I have in the main.js:
(function ($) {
"use strict";
function menu() {
"use strict";
$("#menuToggle").on("click", function () {
$(".header-left").toggleClass("open");
$(".main").toggleClass("open");
});
$(".cross").on("click", function () {
$(".header-left").removeClass("open");
});
$(".nav-link").on("click", function () {
$(".header-left").removeClass("open");
});
}
$(”#menu-left”).load(“assets/html/menu.html”);
$(document).on("ready", function () {
"use strict";
menu();
});
})(jQuery);
The output :
The menu appears. I can see the menu button but the toggle functionality does not work anymore. I tried different things but can't seem to work it out.
How can I solve this ?
Thank you