I'm facing a small issue in adding data div through JSON. I want that in the main div I can show the Role name and inside that all the branches details one by one. Anyhow, I crack some of the parts but somewhere my code is cracking up. Please help me to create this in a proper manner.
My HTML looks like this:
In UI/UX it is taking the branch name of Jenkins too. Don't know where I'm going wrong. And even the last data is not coming.
JSFiddle Link is : https://jsfiddle.net/abhishek_kumar_13092/abLf93t8/139/.
var div = document.createElement('div');
div.id = "mainContainer";
div.className = "mainContainer";
var innerDiv = document.createElement('div');
innerDiv.id = "innerContainer";
innerDiv.className = "innerContainer"
JSONData.forEach(function(data, index) {
div.innerHTML += '<div id=' + data.name + ' class="unitName">' + '<p class="roleName">'+ data.name +'</p>' + '</div>';
document.getElementById("container").appendChild(div);
data.branches.forEach((branch)=>{
innerDiv.innerHTML += '<p id=' + branch.name + ' class="branchName">' + branch.name + '</p>'
document.getElementById(data.name).appendChild(innerDiv);
})
})