Why does querySelector only select the first element and how can I fix this?

Use querySelectorAll instead which would return you a list of node. You then have to iterate over then and attach the event handlers.

document.querySelectorAll(".weekdays").forEach(elem => elem.addEventListener("click",
 () => {
    document.querySelector(".bg-modal").style.display = "flex";
  }));

Leave a Comment