Sorry if this is a duplicate question but I couldn't find anything relating to this specific issue I am having.
--
So what I am trying to do is include HTML files into another HTML file. I'm looking to call in header.html and footer.html to make things more efficient.
I'd normally do this using PHP but I'm looking to keep everything client side as the plan is to use the HTML in hybrid apps for the purpose of testing prototypes in user testing, so I want it all self contained.
I found the below jQuery code that pulls in the header and footer which works great in terms of the HTML and CSS but my issue is that the actions to manage the menu that use jQuery no longer work. They work fine when the all code is on the same page.
<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#content').load("new.html");
});
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>
I am working on my localhost at the moment on Mac but I've also tried this on my server.
I found these links as well but no luck
How to include an HTML file with jQuery?
jQuery .load() call doesn't execute JavaScript in loaded HTML file
https://github.com/LexmarkWeb/csi.js
The all have the same result, content is loaded in no problem but the actions don't work. No error is displayed.
There are additional JS files called locally as well, I am using the Materialize framework.
<!-- Scripts-->
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/init.js"></script>
<script type="application/javascript">
$(".dropdown-trigger").dropdown();
</script>
Materialize https://materializecss.com/bin/materialize.js
This is the file in the init.js
(function($){
$(function(){
$('.sidenav').sidenav();
}); // end of document ready
})(jQuery); // end of jQuery name space
I am at a loss cause I can see anything in the developer console, I've uploaded a sample of the code here http://spudatron.net/test/html-include/ to help understand my setup.
If anyone can help I would be very grateful.