-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocations.js
More file actions
41 lines (33 loc) · 1.11 KB
/
locations.js
File metadata and controls
41 lines (33 loc) · 1.11 KB
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
// var numOne = document.getElementById("num-one");
// var numTwo = document.getElementById("num-two");
// var addSum = document.getElementById("add-sum");
// numOne.addEventListener("input", add);
// numTwo.addEventListener("input", add);
// function add() {
// var one = parseFloat(numOne.value) || 0;
// var two = parseFloat(numTwo.value) || 0;
// addSum.innerHTML = "your sum is: " + (one+two);
// }
var checklist = document.getElementById("checklist");
var items = checklist.getElementsByTagName('li');
var inputs = checklist.getElementsByTagName('input');
for (var i = 0; i < items.length; i++) {
items[i].addEventListener("click", editItem);
inputs[i].addEventListener("blur", updateItem);
inputs[i].addEventListener("keypress", itemKeypress);
}
function editItem() {
this.className = "edit";
var input = this.querySelector("input");
input.focus();
input.setSelectionRange(0, input.value.length);
}
function updateItem() {
this.previousElementSibling.innerHTML = this.value;
this.parentNode.className = "";
}
function itemKeypress(event) {
if (event.which === 13) {
updateItem.call(this);
}
}