Hello fellow developers, I'm facing an issue while working on a project. I have about ten menu items with the same ID, and I want to be able to edit each one when it is clicked. Here's what I tried using JavaScript:
const menuElement = document.querySelector('#menuElement')
const darktheme = document.querySelector('.dark')
loadEventListener()
function loadEventListener() {
menuElement.addEventListener('click', draw)
}
function draw() {
menuElement.style.background = 'var(--primary-color)'
}
However, only the first menu element responds when clicked, but not the rest of them.
Any help would be greatly appreciated. Thank you!