-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (34 loc) · 1.16 KB
/
app.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const taskInput = document.querySelector('#input');
const buttonInput = document.querySelector('#button-input');
const taskList = document.querySelector('#task-list');
buttonInput.addEventListener('click', addTask);
taskList.addEventListener('click', removeTask);
function addTask(e){
if (taskInput.value === "") {
alert('You have entered an empty task, enter the text!')
return
}
//Create <li> Item in HTML
const li = document.createElement('li');
li.className = 'task';
//Create with textnode value html from taskInput
li.appendChild(document.createTextNode(taskInput.value));
//adding link <a>
const link = document.createElement('a');
//adding class to a element
link.className = 'delete-task';
//adding ❌ to a element
link.innerHTML = '<h4> ❌ <h4/>';
//adding link into li
li.appendChild(link);
//adding li into ul html document
taskList.appendChild(li);
taskInput.value = ''
e.preventDefault()
};
//Remove Task
function removeTask(e) {
if(e.target.parentElement.classList.contains('delete-task')) {
e.target.parentElement.parentElement.remove()
}
}