-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 990 Bytes
/
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
"use strict";
import appendCharacterCards from "./api.js";
const charactersContainer = document.querySelector(".characters");
// Add the characters to the DOM
appendCharacterCards(charactersContainer);
charactersContainer.addEventListener("click", (event) => {
let targetParent = event.target.parentElement;
if (targetParent.className === "name") {
// Check and remove extra info from other characters
hideExtraInfo(targetParent);
// toggle display of extra info for a particular character
showExtraInfo(targetParent);
}
});
const showExtraInfo = (targetParent) => {
targetParent.nextElementSibling.classList.toggle("show_element--flex");
};
const hideExtraInfo = (targetParent) => {
document.querySelectorAll(".character__info--extra").forEach((element) => {
if (
element.classList.contains("show_element--flex") &&
element.previousElementSibling !== targetParent
) {
element.classList.remove("show_element--flex");
}
});
};