-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
31 lines (26 loc) · 1.05 KB
/
Copy pathscript.ts
File metadata and controls
31 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const $todoList = document.querySelector('.todos') as HTMLElement;
const $form = document.querySelector('.todo-add-form') as HTMLFormElement;
const $formInput = $form.querySelector('.todo-input') as HTMLInputElement;
const $searchInput = document.querySelector('.header__search') as HTMLInputElement;;
import { TodoList } from './todolist.js';
const myTodoList = new TodoList($todoList);
$todoList.addEventListener('click', (event) => {
const target = event.target as HTMLElement;
if (target.classList.contains('item-actions_type_delete')) {
const todoItem = target.closest('.todo') as HTMLElement;
myTodoList.remove(todoItem.dataset.id as string);
}
});
$form.addEventListener('submit', (event) => {
event.preventDefault();
const value = $formInput.value;
myTodoList.add(value);
$form.reset();
});
$searchInput.addEventListener('input', (event) => {
const input = event.target as HTMLInputElement;
const searchValue = input.value;
myTodoList.search(searchValue);
});
myTodoList.add('Hello');
myTodoList.add('World');