Skip to content

Commit d27ff7d

Browse files
Create javascript
this is the java script file
1 parent 036d082 commit d27ff7d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

To-Do List/javascript

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
let ulTasks = $('#ulTasks')
2+
let btnAdd = $('#btnAdd')
3+
let btnReset = $('#btnReset')
4+
let btnSort = $('#btnSort')
5+
let btnCleanup = $('#btnCleanup')
6+
let inpNewTask = $('#inpNewTask')
7+
8+
function addItem() {
9+
let listItem = $('<li>', {
10+
'class': 'list-group-item',
11+
text: inpNewTask.val()
12+
})
13+
listItem.click(() => {
14+
listItem.toggleClass('done')
15+
})
16+
ulTasks.append(listItem)
17+
inpNewTask.val('')
18+
toggleInputButtons()
19+
}
20+
21+
function clearDone() {
22+
$('#ulTasks .done').remove()
23+
toggleInputButtons()
24+
}
25+
26+
function sortTasks() {
27+
$('#ulTasks .done').appendTo(ulTasks)
28+
}
29+
30+
function toggleInputButtons() {
31+
btnReset.prop('disabled', inpNewTask.val() == '')
32+
btnAdd.prop('disabled', inpNewTask.val() == '')
33+
btnSort.prop('disabled', ulTasks.children().length < 1)
34+
btnCleanup.prop('disabled', ulTasks.children().length < 1)
35+
}
36+
37+
inpNewTask.keypress((e) => {
38+
if (e.which == 13) addItem()
39+
})
40+
inpNewTask.on('input', toggleInputButtons)
41+
42+
btnAdd.click(addItem)
43+
btnReset.click(() => {
44+
inpNewTask.val('')
45+
toggleInputButtons()
46+
})
47+
btnCleanup.click(clearDone)
48+
btnSort.click(sortTasks)

0 commit comments

Comments
 (0)