MENU
Parsing HTML Strings
element.innerHTML points to the content contained by a pair of HTML tags, while element.outerHTML includes the tags themselves as well. element.interText excludes HTML tags.
RESETRUNFULL
<!DOCTYPE html><html><head></head><body><div><input type="checkbox" />:<input/></div><script>setTimeout(()=>{ document.querySelector("div").innerHTML += "<p></p>"; // this erases the text entered into the textbox // and resets the checkbox as well document.querySelector("p").outerHTML = ""; // this erases the <p> just appended
console.log(document.querySelector("div").innerHTML); // <input type="checkbox">:<input>
console.log(document.querySelector("div").outerHTML); // <div><input type="checkbox">:<input></div>
console.log(document.querySelector("div").innerText); // :},10000);</script></body></html>
Alternatively, we can use DOMParser and XMLSerializer, which are more generic in the sense that they can deal with XML and other types of documents as well.
RESETRUNFULL
parser = new DOMParser();doc = parser.parseFromString(HTMLstring, "text/html")// returns an HTMLDocument, which also is a Document.
var s = new XMLSerializer();var str = s.serializeToString(document);saveXML(str);