M
M
Maxim2022-04-19 13:52:22
WordPress
Maxim, 2022-04-19 13:52:22

How to make an event handler on a menu element loaded via wp?

There is a menu created through wordpress, there is a link to the contacts section, a burger opens on the mobile version and a class with overflow: hidden styles is hung on the body; , when you click on the link, the page goes down to the anchor, you need to make sure that the menu closes, but for some reason the event handler for the link added via wp does not work.
Script written at the end of the page:

window.addEventListener("load", function() {
  document.querySelector('.__mPS2id').addEventListener('click', function() {
    document.querySelector('.header-toggler ').classList.remove("header-toggler_open");
  });
});

Menu link
<a href="#contacts" class="menu-link link __mPS2id _mPS2id-h">Контакты</a>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question