jQuery Tabs Next Prev Button: Step-by-Step Form with Bootstrap Tabs

jquery tabs next prev button

Quick answer: To add a jQuery tabs next prev button, put Next and Previous buttons inside each Bootstrap tab pane and, on click, trigger the next or previous tab link with jQuery. This turns tabs into a simple multi-step form. A Bootstrap 5 version without jQuery is included below.

jQuery tabs next prev button for Bootstrap

What the jQuery tabs next prev button code does

It lets visitors move through Bootstrap tabs with Next and Previous buttons instead of clicking the tab titles. This turns a long form into simple steps, for example contact details, project requirements and a final confirmation, which usually improves completion rates.

Step 1: Tabs and buttons HTML

Each tab pane gets its own Next and Previous buttons with the classes btnNext and btnPrevious. This markup uses Bootstrap 4 pills.

form.html
<ul class="nav nav-pills nav-fill mb-3" id="pills-tab" role="tablist">
  <li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#step-1" role="tab">Your information</a></li>
  <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#step-2" role="tab">Requirements</a></li>
  <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#step-3" role="tab">Confirm</a></li>
</ul>

<div class="tab-content">
  <div class="tab-pane fade show active" id="step-1" role="tabpanel">
    <!-- step 1 fields -->
    <button type="button" class="btn btn-primary btnNext">Next</button>
  </div>
  <div class="tab-pane fade" id="step-2" role="tabpanel">
    <!-- step 2 fields -->
    <button type="button" class="btn btn-secondary btnPrevious">Previous</button>
    <button type="button" class="btn btn-primary btnNext">Next</button>
  </div>
  <div class="tab-pane fade" id="step-3" role="tabpanel">
    <!-- summary -->
    <button type="button" class="btn btn-secondary btnPrevious">Previous</button>
    <button type="submit" class="btn btn-success">Submit</button>
  </div>
</div>

Step 2: jQuery for Bootstrap 4

When a button is clicked, the code finds the active tab link, moves to the next or previous list item and clicks its link, so Bootstrap handles the animation.

tabs.js
jQuery(function ($) {
  $('.btnNext').on('click', function () {
    $('#pills-tab .nav-link.active').closest('li').next('li').find('.nav-link').trigger('click');
  });

  $('.btnPrevious').on('click', function () {
    $('#pills-tab .nav-link.active').closest('li').prev('li').find('.nav-link').trigger('click');
  });
});

Bootstrap 5 version without jQuery

Bootstrap 5 no longer needs jQuery. Change data-toggle to data-bs-toggle in the HTML and use this script instead.

tabs-bs5.js
// Bootstrap 5 version (no jQuery). Use data-bs-toggle="pill" in the HTML.
document.addEventListener('click', function (e) {
  var btn = e.target.closest('.btnNext, .btnPrevious');
  if (!btn) return;

  var links = Array.prototype.slice.call(document.querySelectorAll('#pills-tab .nav-link'));
  var index = links.findIndex(function (link) { return link.classList.contains('active'); });
  var next  = btn.classList.contains('btnNext') ? index + 1 : index - 1;

  if (links[next]) {
    bootstrap.Tab.getOrCreateInstance(links[next]).show();
    links[next].scrollIntoView({ behavior: 'smooth', block: 'nearest' });
  }
});

Tips for multi-step tab forms

  • Validate the fields of the current step before moving to the next one.
  • Disable the tab titles if users must follow the steps in order.
  • Show a progress bar or “Step 2 of 3” text so users know how far they are.
  • Keep the submit button only on the last step.

Frequently asked questions

How do I add next and previous buttons to Bootstrap tabs?

Add buttons with btnNext and btnPrevious classes inside each tab pane, then use jQuery (Bootstrap 4) or bootstrap.Tab (Bootstrap 5) to show the next or previous tab when they are clicked.

Can I do this without jQuery?

Yes. The Bootstrap 5 version above uses plain JavaScript and the bootstrap.Tab API.

Does this work with Elementor tabs?

Not directly, because Elementor uses its own tab markup. For Elementor, see my guide to opening an Elementor tab from a link.

Need a custom multi-step form or quote calculator? Get a free quote.

Need help with your own site? Get a free quote or see my recent builds.

Tanvir Hossain Tofan, WordPress developer

Written by Tanvir Hossain Tofan

WordPress & Shopify developer from Bangladesh with 5+ years of experience building custom ACF themes, Elementor sites, plugins and Shopify stores for clients worldwide. Author of the Toofan Stage-to-Live Sync and Talkvara AI Chatbot plugins on WordPress.org.

See my work · Hire me · WhatsApp · YouTube · LinkedIn

Previous Post

Elementor Open Tab on Link Click: Tabs, Accordion & Toggle (No Plugin)

Quick answer: To make Elementor open tab on link c ...

Next Post

Create a WordPress Admin User via functions.php or WP-CLI (Safe Method)

Quick answer: To create a WordPress admin user whe ...

If you find it useful

Buy me a coffee

ACF

Blog

Elementor

HTML JQuery

PHP

Tips & Tricks

WordPress

Copy Link to Clipboard in WordPress: Easy Share Button in 3 Steps

Add a copy link to clipboard button in WordPress w ...

jQuery Cookie Popup: Show a Popup Once Per Day (Easy 3-Step Snippet)

A jQuery cookie popup that shows once per day: HTM ...

Back to top