I can't create a dynamic navigation menu using pure JavaScript
I tried to create a dynamic navigational menu using pure JavaScript but the code doesn't work.
I created an empty unordered list that will be filled automatically using JavaScript
// Identify container, sections and empty unorder list.
const menu = document.getElementById("menu");
const sections = [...document.querySelectorAll("section")]
const nav_menu_items = () => {
let nav_menu_container = '';
sections.foreach(section => {
const sectionID = section.id;
const sectionAtrribute = section.dataset.nav;
nav_menu_container += ` ${sectionAtrribut} `
})
menu.innerHTML = nav_menu_container;
}
nav_menu_items();
This is section 1 so hello
This is section 2 so hello
This is section 3 so hello
This is section 4 so hello