-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (39 loc) · 1.27 KB
/
index.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
47
48
49
const renderCard = (s) => {
const col = document.createElement("div");
col.classList.add("col");
const card = document.createElement("div");
card.classList.add("card");
card.classList.add("hover-shadow");
const img = document.createElement("img");
img.classList.add("card-img-top");
img.alt = s.json;
img.src = s.img;
const body = document.createElement("div");
body.classList.add("card-body");
const title = document.createElement("h5");
title.classList.add("card-ttile");
title.innerText = s.title;
const button = document.createElement("a");
button.href = "test.html?title=" + encodeURI(s.title) + "&json=" + s.json;
button.classList.add("btn");
button.classList.add("btn-primary");
button.innerText = "Ir a " + s.json;
body.appendChild(title);
body.appendChild(button);
card.appendChild(img);
card.appendChild(body);
col.appendChild(card);
return col;
}
function render() {
fetch("index.json")
.then(response => response.json())
.then(data => {
const div = document.getElementById("container");
data.forEach(s => {
const card = renderCard(s);
div.appendChild(card);
});
});
}
render();