Set dropdown initial state to open

Yours is actually the only one that worked for me haha

Hi @martijnrunia ,

I’m trying to achieve exactly the same thing as you, did you ever figure out how to do it?

Thanks! :slight_smile:

Rose

1 Like

Hey @samliew
I tried your trick and it works for setting the first dropdown as open by default. It worked.
But there is a problem, It is not closing when I open other dropdowns.
I want it to close when I click to open any other dropdown…
How to achieve that? Please help!

@harikshore That’s the normal behaviour of Webflow dropdowns. If you want to close all other dropdowns you’ll need some custom code.

its now 2023 and nothing works to target the first dropdown toggle element ID to open. I tried this but the tap function is for mobile. I tried mouseup for desktop. Neither works! Any coders that know how to make this work in 2023?

Mobile

<script>
('#w-dropdown-toggle-0’).trigger(‘tap’);
</script>

Desktop

<script>
$("#w-dropdown-toggle-0").mouseup();
</script>

You want an initial state of open or a permanent state of open?
For a permanent state, I’d probably use CSS to force it to be visible.

For an initial state, try click(). You may also need to look at event bubbling, it depends on how and where Webflow.js event handler is attached.

Not that today this can be tricky because browser have implemented security measures to differentiate between script-clicks and user-clicks, to mitigate clickjacking as a hacking vector.

If you encounter security barriers it’s likely easier to just build your own custom nav from DIVs and interactions.

Not exactly what OP was looking for, but I just found a handy solution to have the/multiple default Dropdown /Accordion element(s) opened in the Designer for easy accessibility for editing copy while in development:

Just add a custom code embed with this css rule:

<style>
.w-dropdown-list {
	display: block;
}
</style>

This makes that all dropdowns are in the “open” state in the Designer. The animation that runs on page-load sets the initial state back to closed.