-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (34 loc) · 1.06 KB
/
main.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
var pTITelement = document.getElementById('json-title')
var pTIMelement = document.getElementById('json-timeframes')
var jsondata = null;
async function getJson() {
let response = await fetch('../data.json');
let data = await response.json()
return data;
}
async function main() {
jsondata = await getJson()
console.log(jsondata)
pTITelement.innerHTML = ''
pTIMelement.innerHTML = ''
for (var i = 0; i < jsondata.length; i++) {
pTITelement.innerHTML += jsondata[i].title + ', '
pTIMelement.innerHTML += jsondata[i].title + ', '
}
}
main();
var DateElements = document.getElementsByClassName('DateButton')
for (let i = 0; i < DateElements.length; i++) {
DateElements[i].addEventListener("click", updateData);
}
// Button function
function updateData(e) {
e = e || window.event;
var targ = e.target || e.srcElement || e;
if (targ.nodeType == 3) targ = targ.parentNode;
e = e.path[0]
var timeframVar = e.innerHTML.toLowerCase()
for (var i = 0; i < jsondata.length; i++) {
console.log(jsondata[i].timeframes[timeframVar])
}
}