Appending div inside a div with js

Getting blank screen.

I have to insert a employee card inside a div with id=”container” with info from JSON file . I have done styling in ’emp’ class.

 load();

function load()
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {

var emp=JSON.parse(xhttp.responseText);
for(var i=0;i<emp.length;i++){
    var d=document.createAttribute('div'); 
    d.className='emp';
    d.innerHTML="Inforamtion";
    var c=document.getElementById('container')
    c.appendChild(d);
    
}

}
};
xhttp.open("GET", "employee.json", true);
xhttp.send(); 
}

Answer

You need to use var d=document.createElement('div'); instead of createAttribute(). If you open the console in the browser after running your current code it will say something like (this is in Firefox) “Uncaught DOMException: Node.appendChild: May not add an Attribute as a child”.