admin管理员组文章数量:1023187
This is the structure of my main menu - different main items that link to separate pages and also have their own submenus:
When I first click on the item, no matter if it's the default dropdown arrow or the name of the main item/main page, it reacts as if the dropdown submenu is being opened. And when I click on it again, it reacts as if I'm opening the page that's also the main item of the dropdown (so, About Us, Service Area etc.), leaving me no option to open the main page (with the first click) or to otherwise close the dropdown menu (with the second click).
I tried to use the Inspector and write a JS code that would differentiate between the two, but it hasn't been working properly. I added it to Elementor Custom Codes, the section:
<script>
document.addEventListener('DOMContentLoaded', function () {
var submenuToggles = document.querySelectorAll('.elementor-nav-menu .sub-arrow');
for (var i = 0; i < submenuToggles.length; i++) {
submenuToggles[i].addEventListener('click', function (e) {
e.stopPropagation();
e.preventDefault();
var submenu = this.parentElement.querySelector(
'.elementor-242 .elementor-element.elementor-element-bc7c611 .elementor-nav-menu--dropdown .elementor-sub-item'
);
if (submenu) {
submenu.classList.toggle('active');
}
});
}
});
</script>
I'm including screenshots of the Inspector tools. This would be the arrow:
And this would be the text:
What can I try next?
This is the structure of my main menu - different main items that link to separate pages and also have their own submenus:
When I first click on the item, no matter if it's the default dropdown arrow or the name of the main item/main page, it reacts as if the dropdown submenu is being opened. And when I click on it again, it reacts as if I'm opening the page that's also the main item of the dropdown (so, About Us, Service Area etc.), leaving me no option to open the main page (with the first click) or to otherwise close the dropdown menu (with the second click).
I tried to use the Inspector and write a JS code that would differentiate between the two, but it hasn't been working properly. I added it to Elementor Custom Codes, the section:
<script>
document.addEventListener('DOMContentLoaded', function () {
var submenuToggles = document.querySelectorAll('.elementor-nav-menu .sub-arrow');
for (var i = 0; i < submenuToggles.length; i++) {
submenuToggles[i].addEventListener('click', function (e) {
e.stopPropagation();
e.preventDefault();
var submenu = this.parentElement.querySelector(
'.elementor-242 .elementor-element.elementor-element-bc7c611 .elementor-nav-menu--dropdown .elementor-sub-item'
);
if (submenu) {
submenu.classList.toggle('active');
}
});
}
});
</script>
I'm including screenshots of the Inspector tools. This would be the arrow:
And this would be the text:
What can I try next?
本文标签:
版权声明:本文标题:javascript - Mobiletablet menu items don't differentiate between clicking on the main menu item and the dropdown arrow - 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745562284a2156233.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论