-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
30 lines (24 loc) · 757 Bytes
/
main.js
File metadata and controls
30 lines (24 loc) · 757 Bytes
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
let btns = document.querySelectorAll(".btns li");
let hOne = document.querySelector("h1");
let img = document.querySelector(".showBox img");
let str = document.querySelector("strong");
let sp = document.querySelector("span");
let total = btns.length;
sp.innerText = total;
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function (e) {
e.preventDefault();
str.innerText = i + 1;
let imgSrc = btns[i].querySelector("a").getAttribute("href");
let txt = btns[i].querySelector("a").innerText;
hOne.innerText = txt;
img.setAttribute("src", imgSrc);
delOn(btns, i);
});
}
function delOn(list, index) {
for (let el of list) {
el.classList.remove("on");
}
list[index].classList.add("on");
}