-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (50 loc) · 1.23 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
$(document).ready(function() {
$('#add').on('click', function() {
IfNotEmpty()
})
$('input[type="text"]').on('keydown', function(e) {
if ( e.key === "Enter" ) {
IfNotEmpty()
}
})
$('#clear-list').on('click', function() {
$('#tasks').empty()
})
$( '#clear-checked' ).on('click', function() {
$('.task').find('.line-through').parent().parent().remove()
})
function IfNotEmpty(argument) {
if ( $('input[type="text"]').val() != '' ) {
NewTask()
}
}
function NewTask() {
let task = $('#new-task').val()
$('#tasks').append(`
<div class="task">
<div class="left">
<input type="checkbox" name="">
<input value="${task}" disabled class="teste">
</div>
<div class="right">
<i class="trash fas fa-trash"></i>
</div>
</div>
`)
$('#new-task').val('')
render()
}
function render() {
const trash = $('i')
trash.on('click', function() {
$(this).parent().parent().remove()
})
$( 'input[type="checkbox"]' ).on('change', function() {
if ( $(this).siblings().hasClass('line-through') ) {
$(this).siblings().removeClass('line-through')
} else {
$(this).siblings().addClass('line-through')
}
})
}
})