I got a jQuery script that includes .html files from an includes folder into my index.html, and it works just fine.
var includes = $('[data-include]');
jQuery.each(includes, function(){
var file = 'includes/' + $(this).data('include') + '.html';
$(this).load(file);
});
I've encountered a problem when I try to include the same .html files but this time I am in a subpages folder trying to achieve the same result, but nothing gets included.
Folder structure:
index.html
assets
includes
-login.html
-header.html
subpages
-contact.html
index.html
<!-- Include search-bar.html -->
<section class="login" data-include="login"></section>
<!-- Include header.html -->
<header class="logo" data-include="header"></header>
<script type="text/javascript" src="assets/lib/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="assets/js/script.js"></script>
contact.html
<!-- Include search-bar.html -->
<section class="login" data-include="login"></section>
<!-- Include header.html -->
<header class="logo" data-include="header"></header>
<script type="text/javascript" src="../assets/lib/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="../assets/js/script.js"></script>