document.querySelectorAll("h2.question").forEach(element => { element.onclick = (e) => { const url = `${window.location.protocol}//${window.location.host}${window.location.pathname}#${e.target.id}`; window.location = url; }; }); document.querySelectorAll("div.music").forEach(element => { console.log(element); element.addEventListener("click", (e) => { const url = `${window.location.protocol}//${window.location.host}/music/${element.id}`; window.location = url; }); });