-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.js
27 lines (26 loc) · 800 Bytes
/
todo.js
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
const textBox = document.getElementById('input');
const error = document.getElementById('error');
const todoList = document.getElementById('listParent');
//logic to create todo
let createList = (text) => {
let list = document.createElement('li');
let todo = document.createTextNode(text);
let doneBtn = document.createElement('button');
let done = document.createTextNode('done');
doneBtn.appendChild(done);
list.appendChild(todo);
list.appendChild(doneBtn);
todoList.appendChild(list);
doneBtn.addEventListener('click',
function() {
this.parentElement.style.display = 'none'
});
}
//function to create todo
function addTodo(){
//ensure input is not empty
textBox.value == '' ? error.innerText = 'empty todo'
createList(`${textBox.value}`);
//reset input
textBox.value = ''
}