Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap toggleable tabs without having tab links

Is there a way to do the following

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li class="active"><a href="#home" role="tab" data-toggle="tab">Home</a></li>
  <li><a href="#profile" role="tab" data-toggle="tab">Profile</a></li>
  <li><a href="#messages" role="tab" data-toggle="tab">Messages</a></li>
  <li><a href="#settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home">...</div>
  <div class="tab-pane" id="profile">...</div>
  <div class="tab-pane" id="messages">...</div>
  <div class="tab-pane" id="settings">...</div>
  <div class="tab-pane" id='extra'> .... </div>

</div>

so there is another tab pane called #extra, but I don't want it to have a link as a tab, but I do want it to be toggleable by some other event

as bootstrap tabs.js works from trigger a tab('show') on a link and not on the pane itself, how do I trigger a tab pane without working on a tab?

note: I aware that the basic operation it does it doing a show() and hide() on the tab pane, but I feel that doing all this manually inhibits me from using callbacks, etc

like image 572
Nick Ginanto Avatar asked Sep 06 '14 10:09

Nick Ginanto


People also ask

How do I toggle between tabs in Bootstrap?

To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a .tab-pane class with a unique ID for every tab and wrap them inside a <div> element with class .tab-content .

How do you make a tab active by default?

Just add the class to your html. This will make the first tab active by default.

How do you convert a tab to an accordion?

tabbed-content" container. Just resize your screen below 800 pixels to see the tabbed interface transforming into an accordion. The change applies only on large screens. On smaller screens (in this example: below 800 pixels) it falls back to the same accordion we have on the previous example.

What is toggle tab?

ToggleTab lets you toggle back and forth between the two most recently selected tabs using a global hotkey. The hotkey is configurable and will work even when chrome doesn't have focus.


1 Answers

You could add the tab for extras and then just hide it

Add this to your nav-tabs:

<li class="hidden"><a href="#extra" role="tab" data-toggle="tab" >Extra</a></li>

Then activate from somewhere else with JavaScript:

$("#launchExtra").click(function() {
    $('#myTab a[href="#extra"]').tab('show')
});

Working demo in jsFiddle


Alternatively, you could just handle the whole thing yourself. The only thing .tab('show') does is remove the active class from all the other nav-tabs and tab-content elements. And then add back the .active class on the appropriate elements.

So first remove all the active elements and then add back the active class:

$("#launchExtra").click(function() {
    $(".nav-tabs .active, .tab-content .active").removeClass("active");
    $("#extra").addClass("active");
});

Working demo in jsFiddle

like image 123
KyleMit Avatar answered Oct 21 '22 13:10

KyleMit