Last active
June 14, 2023 02:28
-
-
Save bradmontgomery/658d16e6359cba593c05d31dd9d5b249 to your computer and use it in GitHub Desktop.
Forms & DOM nodes
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
<h1>Grocery List</h1> | |
<form action="" method="get" id="groceries"> | |
<label for="item">Grocery Item</label> | |
<input type="text" id="item" name="item"> | |
<input type="submit" value="Add Item"> | |
</form> | |
<ul id="grocery-items"> | |
</ul> |
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
/* | |
* This code is for our Grocery List | |
*/ | |
const groceryForm = document.getElementById("groceries"); | |
groceryForm.addEventListener("submit", (event) => { | |
event.preventDefault(); | |
// get user data from form | |
const item = document.getElementById("item").value; | |
// Create a <li> DOM node with the item, and | |
// insert into the page. | |
const li = document.createElement("li"); | |
li.innerHTML = item; | |
const parent = document.getElementById("grocery-items"); | |
parent.appendChild(li); | |
}); | |
// TODO: Click on the <li> elements, to "cross them out" | |
// either use <s> or the css text-decoration: line-through; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment