-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (36 loc) · 1.24 KB
/
app.js
File metadata and controls
41 lines (36 loc) · 1.24 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
var form = document.getElementById('main-form')
var taskToAdd = document.getElementById('taskToAdd');
var tbody = document.querySelector('.task-list');
form.addEventListener('submit', (e) => {
var data = taskToAdd.value;
var date = new Date().toLocaleDateString();
if (data == '') {
showMsg("Please fill the task field", 'error');
} else {
const tr = document.createElement('tr');
tr.innerHTML += `
<td>${data}</td>
<td>${date}</td>
<td><a onclick="removeTask(this)" class = "btn btn-danger"> X </a></td>
`
tbody.appendChild(tr)
showMsg("Task added Successfully", 'success');
}
e.preventDefault()
taskToAdd.value = ""
});
function removeTask(target) {
console.log(target.parentElement.parentElement.remove());
showMsg("Deleted Successfully", 'error');
}
function showMsg(msg, className) {
const div = document.createElement('div');
div.className = className;
div.innerHTML += msg;
const container = document.querySelector('.container');
container.insertBefore(div, form);
setTimeout(() => {
div.style.display = 'none';
}, 1000)
}
// var elem = document.querySelector('#some-element');