Created
February 8, 2022 20:10
-
-
Save Sulkar/5317435e06479f35107d842feb375704 to your computer and use it in GitHub Desktop.
Javascript: universal Create Element function
This file contains 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
//universal Create Element function | |
function createElement(type, props, ...children) { | |
let dom = document.createElement(type); | |
if (props) Object.assign(dom, props); | |
for (let child of children) { | |
if (typeof child != "string" && typeof child != "number") | |
dom.appendChild(child); | |
else dom.appendChild(document.createTextNode(child)); | |
} | |
return dom; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage, creates a table: