Created
July 5, 2019 03:58
-
-
Save sergey-shambir/f99faea0649361d939167f974945c5b0 to your computer and use it in GitHub Desktop.
To-Do App JS, v1
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
function onPageLoaded() { | |
const input = document.querySelector("input[type='text']"); | |
const ul = document.querySelector("ul.todos"); | |
function createTodo() { | |
const li = document.createElement("li"); | |
const textSpan = document.createElement("span"); | |
textSpan.classList.add("todo-text"); | |
const newTodo = input.value; | |
textSpan.append(newTodo); | |
const deleteBtn = document.createElement("span"); | |
deleteBtn.classList.add("todo-trash"); | |
const icon = document.createElement("i"); | |
icon.classList.add("fas", "fa-trash-alt"); | |
deleteBtn.appendChild(icon); | |
ul.appendChild(li).append(textSpan, deleteBtn); | |
input.value = ""; | |
listenDeleteTodo(deleteBtn); | |
} | |
input.addEventListener("keypress", (keyPressed) => { | |
const keyEnter = 13; | |
if (keyPressed.which == keyEnter) { | |
createTodo(); | |
} | |
}); | |
ul.addEventListener("click", onClickTodo); | |
} | |
document.addEventListener("DOMContentLoaded", onPageLoaded); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment