-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (23 loc) · 857 Bytes
/
script.js
File metadata and controls
25 lines (23 loc) · 857 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
document.addEventListener("DOMContentLoaded", () => {
const links = document.querySelectorAll("nav ul li a")
const main = document.querySelector("main")
links.forEach((link) => {
link.addEventListener("click", (event) => {
event.preventDefault()
const file = link.getAttribute("data-file")
fetch(file)
.then((response) => {
if (!response.ok) {
throw new Error("Erro ao carregar o arquivo.")
}
return response.text()
})
.then((html) => {
main.innerHTML = html
})
.catch((error) => {
main.innerHTML = `<p>Erro ao carregar o conteúdo: ${error.message}</p>`
})
})
})
})