Created
September 24, 2020 16:39
-
-
Save johnnyferreiradev/7971bc0c09bb772b3b16661f67c08e25 to your computer and use it in GitHub Desktop.
Function for creating DOM elements
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
const createElement = (elementName, attributes) => { | |
const element = document.createElement(elementName); | |
const attributeAsArray = Object.entries(attributes); | |
attributeAsArray.forEach(([key, value]) => element.setAttribute(key, value)); | |
return element; | |
}; | |
// Example of use | |
const input = createElement('input', { | |
type: 'text', | |
value: 'teste', | |
id: 'input1', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment