Created
May 16, 2020 22:43
-
-
Save tomhodgins/b30524b88a20ad0ac2b91ff19c9ab309 to your computer and use it in GitHub Desktop.
Various ways JS can create an element in an HTML document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ways to create a <div> from JS | |
// write | |
document.write('<div></div>') | |
// createElement | |
document.createElement('<div></div>') | |
// innerHTML | |
document.documentElement.innerHTML += '<div></div>' | |
// createContextualFragment | |
document.createRange().createContextualFragment('<div></div>') | |
// DOMParser | |
new DOMParser().parseFromString('<div></div>', 'text/html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment