Skip to content

Instantly share code, notes, and snippets.

@bendc
Last active February 24, 2017 13:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendc/74f931d4a8bf4e25a8b7 to your computer and use it in GitHub Desktop.
Save bendc/74f931d4a8bf4e25a8b7 to your computer and use it in GitHub Desktop.
Create DOM node from innerHTML-like string
const createNode = html =>
new Range().createContextualFragment(html).firstElementChild;
@bendc
Copy link
Author

bendc commented Feb 24, 2017

Example:

const node = createNode(`
  <section>                                                                                                                                                           
    <h1>Hello world</h1>                                                
  </section>
`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment