Skip to content

Instantly share code, notes, and snippets.

@dragos199993
Created June 28, 2018 13:13
Show Gist options
  • Save dragos199993/577b34ed6fae78f4c78d56947a84b955 to your computer and use it in GitHub Desktop.
Save dragos199993/577b34ed6fae78f4c78d56947a84b955 to your computer and use it in GitHub Desktop.
function appendHtml(el, str) {
var div = document.createElement('div');
div.innerHTML = str;
while (div.children.length > 0) {
el.appendChild(div.children[0]);
}
}
var test = "hi";
var html = `<h1 id="title">Some ${test}</h1><span style="display:inline-block; width=100px;">Some arbitrary text</span>`;
appendHtml(document.body, html); // "body" has two more children - h1 and span.
document.body.appendChild(body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment