I've been trying for hours, just trying to figure out, how to fix a problem. And it's a script to include html with an id of "incl" and a custom attribute called "file" in javascript. And it's returning
"Uncaught TypeError: Cannot set property 'innerHTML' of null
at XMLHttpRequest.xhttp.onreadystatechange (includer.js:13)"
my script is:
var all = document.getElementsByTagName("*");
var fle = [];
var Incl = [];
var nIncl = [];
var xhttp = new XMLHttpRequest();
for (var i = 0, max = all.length; i < max; i++) {
Incl[i] = all[i].getAttribute("id");
if (Incl[i] == "incl") {
nIncl[i] = all[i].getAttribute("id");
fle[i] = all[i].getAttribute("file");
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(nIncl[i]).innerHTML = this.responseText;
}
};
xhttp.open("GET", fle[i], true);
xhttp.send();
}
}
<head id='incl' file="header.html"></head>
<body>
<div id="incl" file="Navlist.txt"></div>
</body>