Last active
June 19, 2020 11:19
-
-
Save JHarry444/2afd89822cc7e868c867460a8aa7edb2 to your computer and use it in GitHub Desktop.
JS function that create an HTML Element and then sets its attributes.
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
function makeElement(eleType, appendTo, attributes) { | |
const element = document.createElement(eleType); | |
for (let attr in attributes) { | |
element[attr] = attributes[attr]; | |
} | |
appendTo.appendChild(element); | |
return element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.g.
makeElement('p', body, { 'innerText': 'bloop', style: 'color: blue'});
Would produce
<p style="color: blue;">bloop</p>