I have a navigation which is a UL that sits in an external html file, and is called into the page with jQuery. However, the navigation will not work on mobile, meaning the menu doesn't drop down when the toggle switch is clicked (the hamburger icon). The navigation loads fine in desktop though.
I know it's a logic issue, but I cannot seem to realize it. I suspect that the toggle icon is dealt with via some JS but since it is not loaded into the document until the jquery fetches it from the external file, then it isn't activated upon as it doesn't yet exist.
I don't think that the jquery is the code in question, as much as how I'm loading it or what I'm missing in the logic to make the code enables the toggle icon to show and hide the navigation.
Nonetheless, here is the code, which is loaded asynchronously and jQuery is declared prior to it loading.
I have an empty div where the menu/navigation is to go like
<div id="navi"></div>
and then
<script type="text/javascript">
$(document).ready(function(){
$('#navi').load('main-nav.html');
});
</script>
The code that handles the click on the toggle icon:
$('.trigger').on('tap', function(e){
e.stopPropagation();
$('#navigation').toggleClass('active'); // Toggle responsive menu
});
However, on mobile or any viewport that changes the nav to a drop down nav, it doesn't open when clicking the toggle icon.