fuzzyworld

hawk / files / public / js / collapsible.js

collapsible.js

Blame: the commit that last changed each line · file · history

731b0b9c 2023-10-15 Pavel Safronov1var coll = document.getElementsByClassName("collapsible");
2var i;
3
4for (i = 0; i < coll.length; i++) {
5 const item = coll[i];
6 if (item.classList.contains("active")) {
7 const content = item.nextElementSibling;
8 content.style.maxHeight = content.scrollHeight + "px";
9 item.after = "▼"
10 }
11 item.addEventListener("click", function () {
12 this.classList.toggle("active");
13 var content = this.nextElementSibling;
14 if (content.style.maxHeight) {
15 content.style.maxHeight = null;
16 item.after = "▶"
17 } else {
18 content.style.maxHeight = content.scrollHeight + "px";
19 item.after = "▼"
20 }
21 });
22}