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
| "use strict";
// Définition des liens
const menu = [
{
text: "Accueil",
href: "accueil.html"
},
{
text: "Blog",
href: "blog.html"
},
{
text: "News",
href: "news.html"
},
{
text: "?",
href: "about.html"
}
];
// Création des éléments
document.addEventListener("DOMContentLoaded", () => {
const docHref = document.location.pathname.split("/").pop();
const oDest = document.querySelector("nav");
menu.forEach((m) => {
oDest.insertAdjacentHTML("beforeend", `<a href="${m.href}" ${m.href == docHref ? 'class="isactive"' : ""}>${m.text}</a>`);
});
}); |
Partager