Last active
June 2, 2020 19:43
-
-
Save brettvaida/3f08da421617b8824755c694e2497071 to your computer and use it in GitHub Desktop.
Basic to-do app
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>To-Do App</h1> | |
<form id="form"> | |
<input id="input" type="text" autocomplete="off"> | |
<button>Create Item</button> | |
</form> | |
<h3>Things To Do</h3> | |
<ul id="list"></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
let form = document.getElementById("form") | |
let input = document.getElementById("input") | |
let list = document.getElementById("list") | |
form.addEventListener("submit", (e) => { | |
e.preventDefault() | |
createItem(input.value) | |
}) | |
function createItem(x) { | |
let listItem = `<li>${x} <button onClick="deleteItem(this)">Delete</button></li>` | |
list.insertAdjacentHTML("beforeend", listItem) | |
input.value = "" | |
input.focus() | |
} | |
function deleteItem(itemToDelete) { | |
itemToDelete.parentElement.remove() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment