-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
59 lines (50 loc) · 1.96 KB
/
Copy pathjavascript.js
File metadata and controls
59 lines (50 loc) · 1.96 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const url = 'https://kitsu.io/api/edge/characters'
let firstChar = document.querySelector("#char-one");
let secondChar = document.querySelector("#char-two");
let thirdChar = document.querySelector("#char-three");
let fourthChar = document.querySelector("#char-four");
let buttons = document.querySelectorAll(".header");
let articles = document.querySelectorAll(".article");
// API
// f67146a92c4344a6aaddc317e31ea9e5
fetch(url)
.then(res => res.json())
.then( res=> {
// console.log("success!", res.data)
// console.log(res.data.length)
let firstDescription = document.createElement("p");
firstDescription.innerHTML = res.data[1].attributes.description;
// console.log(firstDescription)
firstChar.appendChild(firstDescription);
let secondDescription = document.createElement("p");
secondDescription.innerHTML = res.data[3].attributes.description;
// console.log(secondDescription)
secondChar.appendChild(secondDescription);
let thirdDescription = document.createElement("p");
thirdDescription.innerHTML = res.data[0].attributes.description;
// console.log(thirdDescription)
thirdChar.appendChild(thirdDescription);
let fourthDescription = document.createElement("p");
fourthDescription.innerHTML = res.data[9].attributes.description;
// console.log(fourthDescription)
fourthChar.appendChild(fourthDescription);
})
.catch(err => console.log("err", err))
// Accordion
buttons.forEach((button, i) => {
button.addEventListener("click", function (evt) {
evt.preventDefault();
let currentClass = articles[i];
articles.forEach((article) => {
article.classList.remove("active");
});
currentClass.classList.add("active");
});
});
// function removeHTML(str){
// var tmp = document.createElement("DIV");
// tmp.innerHTML = str;
// return tmp.textContent || tmp.innerText || "";
// }
// var html = "/<[^>]*>/g";
// var onlyText = removeHTML(html); ""