I'm using an ajax call to insert a menu.html
inside my index.html
, the call for the jquery script menu-script.js
which handles the hide\show feature of this nested menu is properly loaded and executed into the index.html
(indeed the menu is all closed), however the on.('click', function(){.. etc
is not fired when menu items are clicked.
This is the script:
$(function() {
$('body').addClass('js');
var menu = $('#menu'),
menulink = $('.menu-link'),
menuTrigger = $('.has-subnav > a');
menulink.on('click', function(e) {
console.log('menulink cliked');
e.preventDefault();
menulink.toggleClass('active');
menu.toggleClass('active');
});
menuTrigger.on('click', function(e) {
console.log('menutrugger cliked');
e.preventDefault();
$(this).toggleClass('active').next('ul').toggleClass('active');
});
$('a[href*=#]:not([href=#])').on('click', function() {
console.log('ahref?');
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({ scrollTop: target.offset().top }, 600);
return false;
}
}
});
And the menu.html (part of it):
<div id = "nav-menu" class = "nav-menu">
<a href = "#menu" class = "menu-link has-subnav"><img src = "include/menu.png"></a>
<div id = "menu" class = "menu">
<ul>
<li class="search">
<!-- Google Custom Search -->
</li>
<!-- Core Rulebook -->
<li class = "has-subnav">
<a href = "#">Manuale Base</a>
<ul class = "level-2">
<li><a href = "gettingStarted.html">Per iniziare</a></li>
<li><a href = "races.html">Razze</a></li>
<li><a href = "classes.html">Classi</a></li>
<li><a href = "usingSkills.html">Abilitàs</a></li>