javascript create element innerhtml code example

Example 1: javascript innerhtml

document.getElementById("example").innerHTML = "Paragraph changed!";

Example 2: js innerHTML

document.getElementById("Test").innerHTML = "<p style='color:red;'>Test</p>";

Example 3: javascript create node from 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;
}