-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (41 loc) · 1.69 KB
/
script.js
File metadata and controls
42 lines (41 loc) · 1.69 KB
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
//constants declared for input button and task list area
const taskInput = document.querySelector("#newtask input");
const taskSection = document.querySelector('.tasks');
//listener for the Enter key. Used to add a new task.
taskInput.addEventListener("keyup",(e)=> {
if (e.key == "Enter") {createTask(); } } );
//the onclick event for the 'Add' button
document.querySelector('#push').onclick = function () {
createTask(); }
//the function that creates a task
function createTask() {
if(taskInput.value.length == 0) {
alert("The task field is blank. Enter a task name and try again."); }
else {
//this block insterts HTML that creates each task into the task area div element
taskSection.innerHTML +=
`<div class="task">
<label id="taskname">
<input onclick="updateTask(this)" type="checkbox"id="check-task"></input>
<p>${document.querySelector('#newtask input').value}</p>
</label>
<div class="delete">
<i class="uil uil-trash-alt"></i>
</div>
</div>`;
var current_tasks = document.querySelectorAll(".delete");
for (var i = 0; i < current_tasks.length; i++){
current_tasks[i].onclick = function () {
this.parentNode.remove(); }
}
taskSection.offsetHeight >=300
? taskSection.classList.add("overflow")
: taskSection.classList.remove("overflow");
}
}
function updateTask(task) {
let taskItem = task.parentElement.lastElementChild;
if (task.checked) {
taskItem.classList.add("checked");}
else {taskItem.classList.remove("checked"); }
}