-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (55 loc) · 1.72 KB
/
index.js
File metadata and controls
61 lines (55 loc) · 1.72 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
60
61
const content = [
[
"React is extremely popular",
"It makes building complex, interactive UIs a breeze",
"It's powerful & flexible",
"It has a very active and versatile ecosystem"
],
[
"Components, JSX & Props",
"State",
"Hooks (e.g., useEffect())",
"Dynamic rendering"
],
[
"Official web page (react.dev)",
"Next.js (Fullstack framework)",
"React Native (build native mobile apps with React)"
]
];
const btnWhyReact = document.getElementById("btn-why-react");
const btnCoreFeature = document.getElementById("btn-core-features");
const btnResources = document.getElementById("btn-resources");
const tabContent = document.getElementById("tab-content");
function displayContent(items) {
let listContent = "";
for (const item of items) {
listContent += `<li>${item}</li>`;
}
const list = document.createElement("ul");
tabContent.innerHTML = ""; // clear existing content
list.innerHTML = listContent; // insert new content
tabContent.append(list);
}
function highlightButton(btn) {
// Clear all existing styling / highlights
btnWhyReact.className = "";
btnCoreFeature.className = "";
btnResources.className = "";
btn.className = "active"; // set new style / highlight
}
function handleClick(event) {
const btnId = event.target.id;
highlightButton(event.target);
if (btnId === "btn-why-react") {
displayContent(content[0]);
} else if (btnId === "btn-core-features") {
displayContent(content[1]);
} else {
displayContent(content[2]);
}
}
displayContent(content[0]); // initially show this content
btnWhyReact.addEventListener("click", handleClick);
btnCoreFeature.addEventListener("click", handleClick);
btnResources.addEventListener("click", handleClick);