S
S
seraphi2020-05-27 11:12:14
JavaScript
seraphi, 2020-05-27 11:12:14

How to close the navigation menu of the site by clicking on the anchor link?

Site on wordpress, the menu is made in a standard way through the admin panel, when on the mobile version, I click on any anchor link from the menu, it goes to the right place, but does not close the menu itself. Adding onClick="this.closest('nav').classList.remove('opened') is not possible. How to do it with js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan Krapivin, 2020-05-27
@xevin

in the same way hang your code on onClick on links in the code

document.querySelectorAll('.link').forEach(el => {
  el.addEventListener('click', () => {
    el.closest('nav').classList.remove('opened')
  })
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question