How to trigger dropdown from another button click?

Hi, is it possible to open a dropdown from clicking another button? I need to open a dropdown and then select a tab when a button is clicked elsewhere on the site; I’ve got the tab part working with custom code (just a .click()) but triggering a .click() on the dropdown element isn’t opening it. I’ve also tried .triggerHandler("tap") per the suggestions here and no luck either.

Is this possible or do I need to make a custom dropdown component? It feels like it should be possible to get this working given that tabs work as expected with .click()

Thanks


Here is my site Read-Only: LINK. Note that I’m trying to trigger the Products dropdown but have tried with a plain one without customising it at all, and haven’t been able to get that working either.

Hi @LukeWoolerton,

Welcome to the forum!

It looks like your read-only link didn’t attach properly - would you be able to post it here again?

Thanks!

Hi @mww ,

Thanks for catching that. Here is my read-only link

Thanks!

Hi @LukeWoolerton,

I’m assuming you want the ‘Shop Rooftop Tents’ button to open up the Products dropdown and open the rooftop tents tab?

To do this, set this buttons link URL to # and give the button an id of cta (quick screen recording of this here), then paste this code in Page Settings > Custom Code > Before </body> tag:

<script>
  $('#cta').click(function () {
    $('.w-dropdown-list').show();
    $('#NB-RTT').triggerHandler('click');
    $('.Product-click').addClass('w--open');
    $('.w-dropdown-list').addClass('w--open');
  });
</script>

Hope this helps!