-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (26 loc) · 975 Bytes
/
script.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
let addOnClick=()=>{
//create 'li' item inside of ol element
let inputBox = document.querySelector('.input-box')
let regex = /^\s+$/;
if(regex.test(inputBox.value)<=0 && inputBox.value){
let listItem = document.createElement('li')
listItem.innerHTML =
`<span class="click task-item"> ${document.querySelector('.input-box').value} </span>
<span class="click" style="color:red">(Edit)</span>
<span class="click" style="color:blue">(Remove)</span>`
document.querySelector('.ol-list').appendChild(listItem)
document.querySelector('.input-box').value="";
// create eventlistner for task item
let taskItem = listItem.querySelector('.task-item')
taskItem.addEventListener('click',completeItem)
}
}
let completeItem=(e)=>{
if(e.target.style.textDecoration==="line-through"){
e.target.style.textDecoration='none';
}else{
e.target.style.textDecoration = 'line-through';
}
}
let button = document.querySelector('.add-item')
button.addEventListener('click',addOnClick)