So I have a function that creates a div titled 'musiccard' within the 'content' div and after I have it pull JSON data and use that for the music data. For now it all currently resides in the content div and I was wondering on the best way to move it into the music card which is being created at the same time the data is being pulled.
Here's my js file:
var content = document.getElementById("content");
document.addEventListener("DOMContentLoaded", function() {
init();
title();
headerDescription();
});
function init() {
loadJSON(function(response) {
var json = JSON.parse(response);
var count = Object.keys(json.musics).length;
for(var i=0; i<count; i++){
var div = document.createElement("div");
div.setAttribute("class", "musiccard");
content.appendChild(div);
var h3 = document.createElement("h3");
h3.textContent = json.musics[i].title;
content.appendChild(h3);
var p = document.createElement("p");
p.setAttribute("class", "albumruntime");
p.innerHTML = 'Run Time:' + json.musics[i].running_time + 'min';
content.appendChild(p);
var p = document.createElement("p");
p.setAttribute("class", "musicdescription");
p.innerHTML = json.musics[i].description;
content.appendChild(p);
var img = document.createElement("img");
img.src = json.musics[i].url;
img.setAttribute("class", "albumart");
content.appendChild(img);
}
});
}
<div id="content">to another div?<div id="content">but I want all the other information that currently resides in the content div such as the title, image, description to go into the music card div