0

So I'm trying to get my navbar to close after clicking one of the links on it but I'm having trouble doing that. Here is my code so far:

const toggleButton = document.getElementsByClassName('toggle-button')[0]
const navbarLinks = document.getElementsByClassName('navbar-links')[0]

toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active')
})
PalesaDev
  • 67
  • 6
  • is the `[0]` intentional? Or your question is how to assign a click to ***many*** Elements? If so, what was your research? Please create a [mcve]. – Roko C. Buljan Sep 15 '22 at 13:34
  • Also check the [JQuery documentation](https://api.jquery.com/toggle/) for `.toggle()` – Paul Stoner Sep 15 '22 at 13:42
  • @PaulStoner nowhere in the question is jquery used. Don't add jQuery to a trivial task like this, it's not really needed anymore. – cloned Sep 15 '22 at 14:05
  • @cloned I realize that JQuery is not mentioned. However, it may be the easiest possible solution to the OPs question. – Paul Stoner Sep 15 '22 at 14:07

0 Answers0