Ecommerce Shopify WordPress Discussion

JavaScript .siblings method doesn't work in mobile menu with drop-down sub-links in WordPress

On website I have a Wordpress mobile menu with drop-down sub-links. I want to reveal sublinks using JavaScript .slideToggle only by clicking an arrow and not by clicking a parent link. Now sublinks reveals when I click either arrow or parent link. Function below works, but I don't want to reveal sub-links by clicking a parent link. $(function () { $(".menu-mobile__nav .sub-menu").hide(); $(".menu-mobile__nav .menu-item-has-children").click(function () { $(this).children(".sub-menu").slideToggle(''); }); }); Similar function below should resolve my problem, but it doesn't work at all. Where is the problem? $(function () { $(".menu-mobile__nav .sub-menu").hide(); $(".menu-mobile__nav .menu-item-has-children .arrow").click(function () { $(this).siblings(".sub-menu").slideToggle(''); }); }); Current shortended html code copied from website: <div class="menu-mobile"> <div class="menu-mobile__nav" id="nav"> <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-669"><a href="">Docieplenia</a><span class="arrow"></span> <ul class="sub-menu" style="display: none;"> <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-1364"><a href="">Tynki</a><span class="arrow"></span></li> <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-1365"><a href="">Kleje</a><span class="arrow"></span></li> <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-1366"><a href="">Farby elewacyjne</a><span class="arrow"></span></li> </ul> </li> </div> </div>
I did some testing with your page and I discovered that the .arrow elements are loaded dynamically after the page loads. As a result, your selector doesn't work. All you have to do is replace this line $(".menu-mobile__nav .menu-item-has-children .arrow").click(function () { with this: $(".menu-mobile__nav .menu-item-has-children").on('click', '.arrow', function () {

January 17, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.