Code

Add Previous/Next Buttons to Tabs

Add a next/previous button to Webflow tabs via this Javascript. This allows users to easily navigate between tabs with previous next buttons rather than only the tab links.

Add Previous/Next Buttons to Tabs preview

Add a next/previous button to Webflow tabs via this Javascript. This allows users to easily navigate between tabs with previous next buttons rather than only the tab links.

How to add it

  1. Add a new div tab-wrapper, give it a position of relative and display as inline block and drag your tabs component inside of this.
  2. Add two buttons or two link blocks and add the classes tab-prev and tab-next, give both a position of absolute and position them anywhere inside of the wrapper.
  3. Add the Javascript code to the closing body section of your pages custom code
  4. Publish the site, this won't work inside the designer

The code

Javascript
                      <!-- Add to closing body -->

<script>
// On page ready
var Webflow = Webflow || [];
Webflow.push(function() {

  // For any tab-prev and tab-next clicks
  $('.tab-wrapper').on('click', '.tab-prev, .tab-next', function() {

    // Get direction
    var direction = $(this).hasClass('tab-prev') ? -1 : 1;

    // Get the tab links
    var tablinks = $(this).parent().find('.w-tab-menu');

    // Get index of current tab link, add direction
    var index = tablinks.find('.w--current').index() + direction;

    // If array out of bounds, click on the first
    index = index >= tablinks.children().length ? 0 : index;

    // Update tabs by triggering a "tap" event on the corresponding slide button
    tablinks.find('.w-tab-link').eq(index).trigger('click');

  }); // End click handler

}); // End ready function
</script>

                    

Browse similar code snippets

Categories

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →