-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (25 loc) · 865 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
const list = ["dog","cat","fish","bird","spider"];
const space = document.getElementById("space");
const button = document.getElementById("btn");
const display = document.getElementById('display');
const box = document.getElementById("box")
const angleup = "fa-angle-up"
const angledown = "fa-angle-down"
let isopen = false;
box.addEventListener("click", toggleList);
function toggleList() {
if(isopen){
button.classList.toggle(angleup);
button.classList.toggle(angledown);
space.innerHTML = "";
isopen = !isopen;
}else{
space.innerHTML = list.map((item) => `<li onclick=clickOption(event) >${item}</li>`).join("");
button.classList.toggle(angledown);
button.classList.toggle(angleup);
isopen = !isopen;
}
}
function clickOption(e){
display.innerHTML = e.target.innerHTML
}