/
app.js
40 lines (30 loc) · 945 Bytes
/
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
var ul = document.getElementById('list'),
removeAll = document.getElementById('removeAll'),
add = document.getElementById('add')
add.onclick = () => {
addLi(ul);
};
function addLi(targetUl) {
var inputText = document.getElementById('text').value,
li = document.createElement('li'),
textNode = document.createTextNode(inputText + ' '),
removeButton = document.createElement('button');
document.getElementById('text').value = '';
if (inputText.split(' ').join('').length === 0) {
alert('no input');
return false;
}
removeButton.className = 'removeMe';
removeButton.innerHTML = ' DONE!';
removeButton.setAttribute('onclick', 'removeMe(this);');
li.appendChild(textNode);
li.appendChild(removeButton);
targetUl.appendChild(li);
}
function removeMe(item) {
var parent = item.parentElement;
parent.parentElement.removeChild(parent);
}
removeAll.onclick = function() {
ul.innerHTML = '';
};