Answers for "how to change the innerhtml of an element using js"

0

change element text innerhtml keeping the elements or tags inside

document.getElementById("tagname").firstChild.data = text;
Posted by: Guest on April-19-2021
-2

js create element innerhtml

function createElement( str ) {
    var frag = document.createDocumentFragment();

    var elem = document.createElement('div');
    elem.innerHTML = str;

    while (elem.childNodes[0]) {
        frag.appendChild(elem.childNodes[0]);
    }
    return frag;
}
Posted by: Guest on July-22-2021

Code answers related to "how to change the innerhtml of an element using js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language