Created
April 30, 2017 00:04
-
-
Save mizner/6d643ccf81425ee3d99ac03d618a525e to your computer and use it in GitHub Desktop.
Element Creation Example in 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
const app = document.getElementById('app'); | |
const createElement = (el, text, newEl) => { | |
let textNode = document.createTextNode(text), | |
newElement = document.createElement(newEl), | |
module = newElement.appendChild(textNode); | |
el.appendChild(module) | |
}; | |
// We're using a document fragment to group things up | |
const docFrag = document.createDocumentFragment(); | |
createElement(docFrag, 'Hello Buddy', 'H1'); | |
createElement(docFrag, 'Hello Buddy', 'H1'); | |
createElement(docFrag, 'Hello Buddy', 'H1'); | |
createElement(docFrag, 'Hello Buddy', 'H1'); | |
app.appendChild(docFrag); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment