function addElement(JSONvar) { let cont = 0; const newContainer = document.createElement("div"); newContainer.setAttribute("class", "container-fluid"); const newAcord = document.createElement("div"); newAcord.setAttribute("class", "accordion") newAcord.setAttribute("id", "accordionExample") newContainer.appendChild(newAcord); JSONvar.forEach((item) => { cont++; const newCard = document.createElement("div"); newCard.setAttribute("class", "card"); newAcord.appendChild(newCard); const newCardH = document.createElement("div"); newCardH.setAttribute("class", "card-header"); newCardH.setAttribute("id", "heading" + cont); newCard.appendChild(newCardH); const newH2 = document.createElement("div"); newH2.setAttribute("class", "mb-0"); newCardH.appendChild(newH2); const newbutt = document.createElement("button"); newbutt.setAttribute("class", "btn btn-link btn-block text-left"); newbutt.setAttribute("type", "button"); newbutt.setAttribute("data-bs-toggle", "collapse"); newbutt.setAttribute("data-target", "#collapse" + cont); // id de objetivo newbutt.setAttribute("aria-expanded", "true"); newbutt.setAttribute("aria-controls", "collapseOne"); newH2.appendChild(newbutt); const newH6 = document.createElement("h6"); const newH6txt = document.createTextNode(item.cabecera); newH6.appendChild(newH6txt); newbutt.appendChild(newH6); const newCol = document.createElement("div"); newCol.setAttribute("id", "collapse" + cont); newCol.setAttribute("class", "collapse"); newCol.setAttribute("aria-labelledby", "heading" + cont); newCol.setAttribute("data-parent", "#accordionExample"); newCard.appendChild(newCol); const newCardB = document.createElement("div"); newCardB.setAttribute("class", "card-body"); newCol.appendChild(newCardB); console.log('Cabecera: ' + item.cabecera); item.posiciones.forEach((item) => { console.log('Tipo: ' + item.tipo); console.log('Contenido: ' + item.contenido); if (item.tipo === 'P') { const newp = document.createElement("p"); const newBPtxt = document.createTextNode(item.contenido); newp.appendChild(newBPtxt); newCardB.appendChild(newp); } else { const newimg = document.createElement("img"); newimg.setAttribute("class", "img-fluid img"); newimg.setAttribute("src", "/static/imgs/help/" + item.contenido); newCardB.appendChild(newimg); } } ) const currentDiv = document.getElementById("footer1"); document.body.insertBefore(newContainer, currentDiv); }) }