-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaleries.js
51 lines (36 loc) · 1.84 KB
/
galeries.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
50
51
const wrappForGalleries = document.getElementsByClassName("galeries-bar-container")[0];
fetch('https://jsonplaceholder.typicode.com/albums')
.then(response => response.json())
.then(albums => {
albums.map((album) => {
let galery = document.createElement('div');
galery.classList.add("galery");
let galeryNameH4 = document.createElement('h4');
let galeryNameA = document.createElement('a');
galeryNameA.classList.add("galeryName");
galeryNameA.setAttribute("href", "galery.html?albumId="+ album.id);
galeryNameA.textContent = album.title;
let galeryP = document.createElement('p');
galeryP.textContent = "Author: ";
let galeryAuthorNameA = document.createElement('a');
galeryAuthorNameA.classList.add("authorName");
galeryAuthorNameA.setAttribute("href", "user.html?user_id="+ album.userId);
fetch('https://jsonplaceholder.typicode.com/users?id='+ album.userId)
.then(response => response.json())
.then(userName => {
galeryAuthorNameA.textContent = userName[0].name;
});
let ainside = document.createElement("a");
ainside.classList.add("ainside");
ainside.setAttribute("href", "galery.html?albumId="+ album.id);
let ainsideImg = document.createElement("img");
ainsideImg.setAttribute('src', "https://picsum.photos/370/170?random="+ album.id)
wrappForGalleries.append(galery);
galery.append(galeryNameH4);
galeryNameH4.append(galeryNameA);
galery.append(galeryP);
galeryP.append(galeryAuthorNameA);
galery.append(ainside);
ainside.append(ainsideImg);
})
})