Created
March 22, 2023 02:31
-
-
Save damoclark/e7042f9266515aa97151d47fee1989a7 to your computer and use it in GitHub Desktop.
Very basic html template function for javascript
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
/** | |
* 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