-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (83 loc) · 2.78 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Hi this is a todo list</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<!--<body>-->
<!--<div class="container">-->
<!--<div class="row">-->
<!--<div class="col-md-12">-->
<!--<h1>Todos</h1>-->
<!--<form id="todo-form">-->
<!--<div class="form-group">-->
<!--<label>Todo text</label>-->
<!--<input type="text" class="form-control" id="todo-text">-->
<!--</div>-->
<!--<button class="btn btn-primary" type="submit">Add todo</button>-->
<!--</form>-->
<!--<ul id="todo-list">-->
<!--</ul>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</body>-->
<body>
<h1>Todos</h1>
<form id="todo-form">
<input type="text" id="todo-text">
<button type="submit">Add todo</button>
</form>
<ul id="todo-list">
</ul>
</body>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$('#todo-form').on('submit', function (e) {
e.preventDefault();
var todo = $('#todo-text').val();
// addTodo(todo);
addTodoFancy(todo)
})
// this is great and all, but weird in that we are making a bunch of click listeners
function addTodo (text) {
var newTodo = $('<li>').text(text)
newTodo.data('done', false)
newTodo.append($('<button>').text('delete').on('click', function() {
$(this).parent().remove();
}))
newTodo.on('click', function () {
if ($(this).data('done') == false) {
$(this).css('text-decoration', 'line-through')
$(this).data('done', true);
} else {
$(this).css('text-decoration', 'none')
$(this).data('done', false);
}
})
$('#todo-list').append(newTodo);
}
function addTodoFancy(text) {
var newTodo = $('<li>').text(text)
newTodo.data('done', false)
newTodo.append($('<button>').text('delete'))
$('#todo-list').append(newTodo);
}
$('#todo-list').on('click', 'li', function () {
console.log($(this))
if ($(this).data('done') == false) {
$(this).css('text-decoration', 'line-through')
$(this).data('done', true);
} else {
$(this).css('text-decoration', 'none')
$(this).data('done', false);
}
})
$('#todo-list').on('click', 'button', function () {
$(this).parent().remove();
})
})
</script>
</html>