Move js into its own file

This commit is contained in:
Katy248
2024-06-01 11:20:43 +03:00
parent 5a73cf5341
commit 6409642dc3
2 changed files with 25 additions and 28 deletions
+23
View File
@@ -0,0 +1,23 @@
function loadPage(section, page) {
let buttons = document.getElementById(section).getElementsByTagName("button");
let currSel;
for (let i in buttons) {
if (buttons[i].classList?.contains("sel-btn")) {
if (page - 1 == i) return;
else {
currSel = buttons[i];
break;
}
}
}
fetch(section + "_page" + page + ".html")
.then((response) => response.text())
.then((data) => {
document.getElementById(section + "-content").innerHTML = data;
if (currSel) {
currSel.classList.remove("sel-btn");
}
document.getElementById(section).getElementsByTagName("button")[page - 1].classList.add("sel-btn");
});
}