I have the below code for creating some simple JSON data, and iterating it over into my page's HTML.
The problem is this code is returning 'string' undefined error without the on load function.
With the on load function present, it is seemingly just ignored and doesn't execute at all (no errors), however, when I add the below code directly into the browser console it executes fine.
Any thoughts?
window.addEventListener('load', function() {
var json =[{
"Name": "sample data",
"Type": "lorem ip sum lorem sample",
"DateModified": "6/14/2218 17:22:50",
"Size": "2 KB",
}, {
"Name": "sample Q",
"Type": "lorem ipsum",
"DateModified": "5/11/2218 7:32:10",
"Size": "6999 KB",
}, {
"Name": "sample x",
"Type": "blah blah",
"DateModified": "6/26/2218 10:29:59",
"Size": "8999 KB",
},
];
var string ="";
for (i in json) {
string +='<div class="row"><div class="col-md-15 col-sm-1"><input type="checkbox" id="all" name="all" value="all"></div><div class="col-md-15 col-sm-4"><span class="folders">'+json[i].Name+'</span></div><div class="col-md-15 col-sm-3"><span class="directory">'+json[i].Type+'</span></div><div class="col-md-15 col-sm-3"><span class="date-stamp">'+json[i].DateModified+'</span></div><div class="col-md-15 col-sm-1"><span class="date-size">'+json[i].Size+'</span></div></div>';
};
document.getElementsByClassName('change').innerHTML =string
});