Last active
March 4, 2021 14:47
-
-
Save heytheretaylor/ab363be2228bf5c5981c38c968184374 to your computer and use it in GitHub Desktop.
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
<style> | |
html{ | |
background-color: #000; | |
opacity: 0.9; | |
} | |
li{ | |
color: white; | |
user-select: none; | |
} | |
.completed { | |
text-decoration: line-through; | |
color: red | |
} | |
h1 { | |
color: grey; | |
font-size: 4.5em | |
} | |
</style> | |
<h1>MY Todo List App</h1> | |
<button id="add_btn">Add Todo:</button> | |
<input id="input_field"> | |
<ul id="todo_list"> | |
</ul> | |
<script> | |
const btn = document.getElementById('add_btn') | |
const todoList = document.getElementById('todo_list') | |
const inputField = document.getElementById('input_field') | |
btn.addEventListener('click', addToDo) | |
function addToDo(e){ | |
const value = inputField.value | |
if(value === ''){ | |
return | |
} | |
const newTodo = document.createElement('li') | |
newTodo.innerText = value | |
newTodo.addEventListener('click', completeTodo) | |
todoList.append(newTodo) | |
inputField.value = '' | |
} | |
function completeTodo(e){ | |
const todo = e.target | |
console.log(todo.innerText) | |
if(todo.classList.contains('completed')){ | |
todo.classList.remove('completed') | |
} else { | |
todo.classList.add('completed') | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment