Answer the question
In order to leave comments, you need to log in
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");
});
});
<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 questionAsk a Question
731 491 924 answers to any question