Skip to content

Instantly share code, notes, and snippets.

@damoclark
Created March 22, 2023 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damoclark/e7042f9266515aa97151d47fee1989a7 to your computer and use it in GitHub Desktop.
Save damoclark/e7042f9266515aa97151d47fee1989a7 to your computer and use it in GitHub Desktop.
Very basic html template function for javascript
/**
* Create an Element from string using template tag for insertion into DOM
* @param {string} html
* @return {Element}
*/
function createElement(html) {
if(html === null || html === undefined)
return null ;
const element = window.document.createElement('template') ;
element.innerHTML = html ;
return element.content.firstElementChild
}
export default createElement ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment