Nov 14, 2019
White Arrow icon
Back to all Elements

Current Class on Dropdown

Makes the dropdown element (usually inside navigations) indicate when a current state is active on one of the pages within.

What this code does is to check if there's a child element under the dropdown with current state ('.w--current' class added by webflow), and apply the same class to the parent dropdown element.

We start by adding this short code to the Project's custom code section, so this will work globally on any page in the project.. We can also add this manually to every page we have a sub level dropdown menu.

<script>

 $('.w-dropdown').each(function() {

   var hasActiveLink = $(this).find('.w--current').length > 0;

   $(this).find('.w-dropdown-toggle').addBack().toggleClass('w--current', hasActiveLink);

 });

</script>

Copy

Based on Samuel Liew code from here.

Preview:

Share:

The videos Kurzgesagt channel creates are so beautifully animated, that I almost forget that I learn so much while watching them!

Might also interest you:

Webflow Dashboard Workspaces Hack

Webflow UI Hack
Code
CSS

Convert the Workspaces dropdown to an open sidebar with custom order.

Read more
White Arrow icon

Dynamic Height

Code
Tricks
JavaScript

A (custom code) solution that combines CSS variables and Vanilla JavaScript for the shrinking / growing of browser top & bottom bars.

Read more
White Arrow icon

Desktop Grid, Mobile Slider

Cloneable
Tricks
Layout

Change Webflow's Slider to act as a "regular" grid block on desktop, but go back to Slider on Tablet and smaller screens.

Read more
White Arrow icon