Skip to content

Instantly share code, notes, and snippets.

@brettvaida
Last active June 2, 2020 19:43
Show Gist options
  • Save brettvaida/3f08da421617b8824755c694e2497071 to your computer and use it in GitHub Desktop.
Save brettvaida/3f08da421617b8824755c694e2497071 to your computer and use it in GitHub Desktop.
Basic to-do app
<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>
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