-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (37 loc) · 1.26 KB
/
index.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
document.getElementById("addBtn").onclick = function(){
if(document.getElementById("textId").value === "" ){
alert("You should enter at least 1 character")
}
else{
console.log("hello")
let div = document.getElementById('Tasks');
let p = document.createElement("p");
p.textContent = document.getElementById("textId").value;
p.setAttribute("class","taskText");
let checkBox = document.createElement("INPUT");
checkBox.setAttribute("type", "checkbox");
checkBox.setAttribute("class", "checkboxId");
checkBox.addEventListener('input', function(){
if(this.checked){
p.style.color = "red";
p.style.textDecoration = "line-through";
}
else{
p.style.color = "black";
p.style.textDecoration = "";
}
})
document.getElementById("textId").value = ""
p.appendChild(checkBox);
div.appendChild(p);
}
}
document.getElementById("removeBtn").onclick = function(){
let checkBoxes = document.getElementsByClassName("checkboxId");
for(let i = 0; i< checkBoxes.length; i++){
if(checkBoxes[i].checked){
document.getElementsByClassName("taskText")[i].remove();
i--;
}
}
}