-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (26 loc) · 972 Bytes
/
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
// Declaring Variables
let inputbtn = document.getElementById('input-but');
let addBtn = document.getElementById('add-button');
let list = document.getElementById('text');
addBtn.addEventListener('click', getVal)
// Adding Function to Add New task
function getVal() {
let value = inputbtn.value;
if (value === "") {
alert("Please fill out this field.")
}
else {
let newElement = document.createElement('li')
let liText = document.createTextNode(value)
newElement.appendChild(liText)
list.appendChild(newElement)
// Removing Task by double click on the list item
newElement.ondblclick=(e)=>newElement.remove()
// Highlighting list item on click
newElement.addEventListener('click', highLighter)
function highLighter(){
newElement.style.backgroundColor = 'gray'
}
}
document.myForm.reset()
}