Appending div inside a div with js Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Appending div inside a div with js without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.


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'); 
    var c=document.getElementById('container')

};"GET", "employee.json", true);


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”.

We are here to answer your question about Appending div inside a div with js - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji