textContent
replaces all the content in the element.
http://jsfiddle.net/2nmL7v5b/6/
You have to something like this
var infoDiv = document.createElement("div");
infoDiv.setAttribute("class", "text-block");
var bio = document.createElement("strong");
bio.textContent = "Bio";
infoDiv.appendChild(bio);
var spanElem = document.createElement("div");
spanElem.textContent = "Full";
infoDiv.appendChild(spanElem)
document.getElementsByTagName("body")[0].appendChild(infoDiv)
<body>
</body>
Or if you don’t want to use span
tag you can use innerHTML
also like
http://jsfiddle.net/2nmL7v5b/11/
var infoDiv = document.createElement("div");
infoDiv.setAttribute("class", "text-block");
var bio = document.createElement("strong");
bio.textContent = "Bio";
infoDiv.appendChild(bio);
infoDiv.innerHTML += "Full";
document.getElementsByTagName("body")[0].appendChild(infoDiv)
<body>
</body>
solved AppendChild Is Not working with textcontent (javascript) [closed]