-
Notifications
You must be signed in to change notification settings - Fork 6
/
todoit.js
executable file
·40 lines (33 loc) · 1.12 KB
/
todoit.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
var TODOit = function (el) {
var parent = document.getElementById(el)
var form = document.createElement('form')
var input = document.createElement('input')
input.setAttribute('type', 'text')
input.setAttribute('placeholder', 'TODO...')
var addBtn = document.createElement('button')
// define callback for 'add' button:
addBtn.onclick = function (e) {
e.preventDefault()
var newTodo = document.createElement('p')
var todoTxt = document.createTextNode(input.value)
newTodo.appendChild(todoTxt)
// define callback for strike-through:
newTodo.onclick = function (e) {
e.preventDefault()
if (this.style.getPropertyValue('text-decoration') === 'line-through') {
this.style.setProperty('text-decoration', 'none')
} else {
this.style.setProperty('text-decoration', 'line-through')
}
}
parent.appendChild(newTodo)
input.value = ''
}
var btnTxt = document.createTextNode('Add TODO')
addBtn.appendChild(btnTxt)
// put everything on the page:
form.appendChild(input)
form.appendChild(addBtn)
parent.appendChild(form)
}
window.TODOit = TODOit