Question

How can I replace the innerHTML? Replace innerHTML on createElement, setAttribute throughout the application impossible.

Moderator

Was it helpful?

Solution

document.getElementById("information").innerHTML = info[0].getAttribute("text");

One line of code turns into tens ... Not very practical, but no other way.

var informationDiv1 = document.createElement('div');
var informationDiv2 = document.createElement('div');
var informationDiv3 = document.createElement('div');
var informationImg = document.createElement('img');

informationDiv1.setAttribute("class", "panel panel-primary");
informationDiv1.setAttribute("style", "margin: 20px;");
informationDiv2.setAttribute("class", "panel-body text-justify");
informationDiv2.textContent = info[0].getAttribute("text");
informationDiv3.setAttribute("class", "text-center");
informationImg.setAttribute("src", "/img/gif2.gif");
informationImg.setAttribute("style", "width: 235px; margin-bottom: 20px;");
informationImg.setAttribute("class", "img-thumbnail");

informationDiv1.appendChild(informationDiv2);
informationDiv3.appendChild(informationImg);
informationDiv1.appendChild(informationDiv3);

document.getElementById("information").appendChild(informationDiv1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top