Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button to Trigger Nav-Tab with Twitter Bootstrap

This button triggers the next tab to load content, but the tab itself does not switch, it remains on the first tab..

<br><a class="btn btn-primary" href="#tab2" data-toggle="tab">Review</a><br>

Here is the code for nav nav-tabs:

  <ul class="nav nav-tabs">
    <li class="active"><a href="#tab1" data-toggle="tab">Shipping</a></li>
    <li><a href="#tab2" data-toggle="tab">Quantities</a></li>
    <li><a href="#tab3" data-toggle="tab">Summary</a></li>
  </ul>

ANY SOLUTION for switching both the tab&content IS APPRECIATED

..perhaps a way to change the button to trigger the next() function in * bootstrap-tab.js v2.3.1:

  , activate: function ( element, container, callback) {
      var $active = container.find('> .active')
        , transition = callback
            && $.support.transition
            && $active.hasClass('fade')

      function next() {
        $active
          .removeClass('active')
          .find('> .dropdown-menu > .active')
          .removeClass('active')

        element.addClass('active')

        if (transition) {
          element[0].offsetWidth // reflow for transition
          element.addClass('in')
        } else {
          element.removeClass('fade')
        }

        if ( element.parent('.dropdown-menu') ) {
          element.closest('li.dropdown').addClass('active')
        }

        callback && callback()
      }

      transition ?
        $active.one($.support.transition.end, next) :
        next()

      $active.removeClass('in')
    }
  }
like image 723
sourcingsynergy Avatar asked May 09 '13 13:05

sourcingsynergy


People also ask

How to create tab based navigation using Twitter Bootstrap?

You may create tab based dropdown navigation using Twitter Bootstrap. There are four CSS classes - .dropdown, .dropdown-toggle, .dropdown-menu and .caret which you need in addition to the .nav and .nav-tabs classes for that.

How to create stacked or vertical pills based navigation using Twitter Bootstrap?

Similar to creating Stacked or Vertical tabs, you need a CSS class, in addition, to create a Stacked or Vertical pills based navigation. It is .nav-stacked class, which resides from line number 2281 to 2309 contain styles for .nav-stacked. Following is an example. Example of stacked or vertical pills based Navigation using Twitter Bootstrap

How to make tabbable Nav work with jQuery?

You need two JS files included to make the Tabbable Nav work - jquery.js and bootstrap-tab.js; both are located with docs/assets/js folder. Following example shows Tabbable Nav in action.

How to trigger a tab with the same href attribute?

By changing 'data-toggle' to 'data-trigger' for the triggering link, the following code can trigger any tab with the same HREF attribute, for all triggers with similar markup. Show activity on this post. Show activity on this post. Show activity on this post. Thanks for contributing an answer to Stack Overflow!


1 Answers

You could assign your Review button a click handler using jQuery...

JS:

$('#btnReview').click(function(){
  $('.nav-tabs > .active').next('li').find('a').trigger('click');
});

HTML:

<a class="btn btn-primary" href="#" id="btnReview">Review</a>

Working Demo

like image 153
Zim Avatar answered Sep 27 '22 20:09

Zim