I have the following javascript:
// create a new article tag
var elem = document.createElement(\'article\');
// append the article to the comments list
docu
Taken from the MDN-site :
Element.innerHTML property sets or gets the HTML syntax describing the element's descendants.Note: If a
,,ornode has a child text node that includes the characters(&), (<),or(>),innerHTMLreturns these characters as &, < and > respectively. UseNode.textContentto get a correct copy of these text nodes' contents.outerHTML
The
outerHTMLattribute of theelementDOM interface gets the serialized HTML fragment describing the element including its descendants. It can be set to replace the element with nodes parsed from the given string.innerHTML vs. outerHTML :
Use
innerHTMLas default. This replaces only the content (if using i.e. "=") inside the current element referred to. If you are usingouterHTML, then the element referred to will also be replaced.Demo:
var h20 = document.getElementById("h20"), h21 = document.getElementById("h21"); var ran = false; console.log("'h20' innerHTML (1) =", "'" + h20.innerHTML + "'", "outerHTML (1) =", "'" + h20.outerHTML + "'"); console.log("'h21' innerHTML (1) =", "'" + h21.innerHTML + "'", "outerHTML (1) =", "'" + h21.outerHTML + "'"); document.getElementById("button").onclick = evt => { if (ran) return false; h20.innerHTML = "innerHTML"; h21.outerHTML = "outerHTML"; console.log("'h20' innerHTML (2) =", "'" + h20.innerHTML + "'", "outerHTML (2) =", "'" + h20.outerHTML + "'"); console.log("'h21' innerHTML (2) =", "'" + h21.innerHTML + "'", "outerHTML (2) =", "'" + h21.outerHTML + "'"); ran = true }