-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodolist.html
116 lines (112 loc) · 4.2 KB
/
todolist.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Add course page</title>
</head>
<body>
<style>
body{
height: 92vh;
background: #03dfff;
background: linear-gradient(139deg,#03dfffcb 0%,#ff0381b6 90%);
font-family: 'Times New Roman', Times, serif;
}
#add{
background-color: green;
color: white;
}
h1{
text-align: center;
justify-content: center;
margin-top: 50px;
color:rgb(10, 10, 10);
text-transform: uppercase;
}
.form-control{
font-weight: 30px;
font-size: 20px;
background-color: #fff;
}
.form-control:focus{
border: 3px solid black;
border-radius: 1 5px;
}
#add{
border: 1px solid black;
border-radius: 5px;
}
#btn1{
border: 1px solid black;
border-radius: 5px;
}
</style>
<h1>To Do List</h1>
<div class="container mt-5 col-6" >
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Add Task Name" aria-label="Recipient's username" aria-describedby="button-addon2">
<button id="add" class="btn btn-outline-success" type="button" id="button-addon2">Add</button>
</div>
<ul id="parentli" class="list-group">
<li class="list-group-item d-flex justify-content-between">
<h3 class="flex-grow-1">Writing</h3>
<button id="btn1" class="btn btn-warning mx-3" onclick="editChapter(this)">Edit</button>
<button id="btn1" class="btn btn-danger" onclick="removeChapter(this)">Remove</button>
</li>
</ul>
</div>
<script>
let addBtn=document.getElementById('add')
addBtn.addEventListener('click',addChapter)
let parentList=document.getElementById('parentli')
function addChapter(e){
if(parentList.children[0].className=="emptyMsg"){
parentList.children[0].remove()
}
let currentBtn=e.currentTarget;
let currentInput=currentBtn.previousElementSibling
let currentChapterName=currentInput.value
let newLi=document.createElement('li')
newLi.className="list-group-item d-flex justify-content-between"
newLi.innerHTML= `<h3 class="flex-grow-1">${currentChapterName}</h3>
<button class="btn btn-warning mx-3">Edit</button>
<button class="btn btn-danger" onclick="removeChapter(this)">Remove</button>`
parentList.appendChild(newLi)
}
function removeChapter(currElement){
currElement.parentElement.remove()
if(parentList.children.length <= 0){
let newEmptyMsg=document.createElement('h3')
newEmptyMsg.classList.add('emptyMsg')
newEmptyMsg.textContent="Nothing is here. Please Add a Task!!"
newEmptyMsg.style.textAlign='center'
newEmptyMsg.style.color='black'
parentList.appendChild(newEmptyMsg)
}
}
function editChapter(currElement){
if(currElement.textContent=='Done'){
currElement.textContent='Edit'
let currentChapterName=currElement.previousElementSibling.value
let currHeading = document.createElement('h3');
currHeading.className="flex-grow-1"
currHeading.textContent=currentChapterName
currElement.parentElement.replaceChild(currHeading,currElement.previousElementSibling)
}
else{
currElement.textContent="Done"
let currentChapterName=currElement.previousElementSibling.textContent
let currInput=document.createElement('Input');
currInput.type="text"
currInput.ariaPlaceholder="Chapter Name"
currInput.className="form-control"
currInput.value=currentChapterName
currElement.parentElement.replaceChild(currInput,currElement.previousElementSibling)
}
}
</script>
</body>
</html>