Quantcast
Viewing all articles
Browse latest Browse all 31

Inject HTML From a String of HTML

Say you have some HTML that is a string:

let string_of_html = `
  <div>Cool</div>
`;

Maybe it comes from an API or you've constructed it yourself from template literals or something.

You can use innerHTML to put that into an element, like:

document.body.innerHTML = string_of_html;

// Append it instead
document.body.innerHTML += string_of_html;
(more…)

Viewing all articles
Browse latest Browse all 31

Trending Articles