Last active
March 21, 2022 01:05
-
-
Save tinajeong/323fdf994723a45d27433a9cb632be59 to your computer and use it in GitHub Desktop.
이전에 개발한 TODO LIST 소스
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
const newTodoForm = document.getElementById('newTodoForm') | |
const newTodo = document.getElementById('newTodo') | |
const todoList = document.getElementById('todoList') | |
const todoListEls = todoList.getElementsByTagName('li') | |
let todoListState = [] | |
// todoListState 초기화 | |
for (let i = 0; i < todoListEls.length; i++) { | |
todoListState.push(todoListEls[i].innerText) | |
} | |
// todoList에 할일(Todo)를 추가할 수 있다. | |
function addTodo (todoText) { | |
todoListState.push(todoText) | |
console.log(todoListState) | |
const newTodoLi = document.createElement('li') | |
newTodoLi.className = 'close' | |
newTodoLi.innerText = todoText | |
newTodoLi.addEventListener('click', e => { | |
e.preventDefault() | |
removeTodo(newTodoLi) | |
}) | |
todoList.appendChild(newTodoLi) | |
} | |
// todoList의 할 일을 삭제할 수 있다. | |
function removeTodo (todoLi) { | |
todoListState = todoListState.filter(function (value, index) { | |
return value != todoLi.innerText | |
}) | |
console.log(todoListState) | |
todoLi.style.display = 'none' | |
} | |
newTodoForm.addEventListener('submit', e => { | |
e.preventDefault() | |
addTodo(newTodo.value) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment