-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (25 loc) · 788 Bytes
/
index.js
File metadata and controls
34 lines (25 loc) · 788 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
31
32
33
34
async function setHTML(filePath, element) {
try {
const response = await fetch(filePath);
const htmlContent = await response.text();
element.innerHTML = htmlContent;
} catch (error) {
console.error('Error loading file:', error);
}
}
async function injectHTML(event) {
console.log(event);
const file = event?.target?.attributes.getNamedItem("href")?.value;
const contentDiv = document.getElementById("content");
console.log(file);
console.log(contentDiv);
setHTML(file, contentDiv);
}
window.onload = (event) => {
console.log('Hello!\n');
const links = document.getElementsByClassName('section');
setHTML("/home.html", document.getElementById("content"));
for (const link of links) {
link.addEventListener('click', injectHTML);
}
}