A Pen by Rodrigo Pombo on CodePen.
Created
April 25, 2017 21:21
-
-
Save pomber/868056ad6c304826db91c09f92c4bce9 to your computer and use it in GitHub Desktop.
DOM review
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
<div id="root"> | |
</div> |
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
// Get an element by id | |
const domRoot = document.getElementById("root"); | |
// Create a new element given a tag name | |
const domInput = document.createElement("input"); | |
// Set a property value | |
domInput["value"] = "Hi world"; | |
// Handle events | |
domInput.addEventListener("change", e => alert(e.target.value)); | |
// Create a text node | |
const domText = document.createTextNode(""); | |
// Set text node content | |
domText["nodeValue"] = "Foo"; | |
// Append an element | |
domRoot.appendChild(domInput); | |
// Append a text node (same as previous) | |
domRoot.appendChild(domText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment