Bootstrap with CSS
- Bootstrap - Responsive utilities
- Bootstrap - Helper Classes
- Bootstrap - Images
- Bootstrap - Buttons
- Bootstrap - Forms
- Bootstrap - Tables
- Bootstrap - Code
- Bootstrap - Typography
- Bootstrap - CSS Overview
- Bootstrap - Grid System
Bootstrap Layout Components
- Bootstrap - Wells
- Bootstrap - Panels
- Bootstrap - List Group
- Bootstrap - Media Object
- Bootstrap - Progress Bars
- Bootstrap - Alerts
- Bootstrap - Thumbnails
- Bootstrap - Page Header
- Bootstrap - Jumbotron
- Bootstrap - Badges
- Bootstrap - Labels
- Bootstrap - Pagination
- Bootstrap - Breadcrumb
- Bootstrap - Navbar
- Bootstrap - Navigation Elements
- Bootstrap - Input Groups
- Bootstrap - Button Dropdowns
- Bootstrap - Button Groups
- Bootstrap - Dropdowns
- Bootstrap - Glyphicons
Bootstrap Plugins
- Bootstrap - Affix Plugin
- Bootstrap - Carousel Plugin
- Bootstrap - Collapse Plugin
- Bootstrap - Button Plugin
- Bootstrap - Alert Plugin
- Bootstrap - Popover Plugin
- Bootstrap - Tooltip Plugin
- Bootstrap - Tab Plugin
- Bootstrap - Scrollspy Plugin
- Bootstrap - Dropdown Plugin
- Bootstrap - Modal Plugin
- Bootstrap - Transition Plugin
- Bootstrap - Plugins Overview
Bootstrap Demos
- Bootstrap - featured Demo
- Bootstrap - Icons Demo
- Bootstrap - Social Icons Demo
- Bootstrap - Calendar Demo
- Bootstrap - Map Demo
- Bootstrap - Caption Demo
- Bootstrap - Tabbed slider Demo
- Bootstrap - Ajax Demo
- Bootstrap - Admin Interface Demo
- Bootstrap - Alert Demo
- Bootstrap - Time line Demo
- Bootstrap - Slider Demo
- Bootstrap - Material Design Demo
- Bootstrap - Blog Demo
- Bootstrap - Navigation Demo
- Bootstrap - Responsive Demo
- Bootstrap - Images Demo
- Bootstrap - Buttons Demo
- Bootstrap - Form Demo
- Bootstrap - Table Demo
- Bootstrap - Grid Demo
Bootstrap Useful Resources
- Bootstrap - Discussion
- Bootstrap - Useful Resources
- Bootstrap - Quick Guide
- Bootstrap - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Bootstrap - Tab Plugin
Tabs were introduced in the chapter
. By combining a few data attributes, you can easily create a tabbed interface. With this plug-in you can transition through panes of local content in tabs or pills, even via drop down menus.If you want to include this plugin functionapty inspanidually, then you will need tab.js. Else, as mentioned in the chapter, you can include bootstrap.js or the minified bootstrap.min.js.
Usage
You can enable tabs in the following two ways −
Via data attributes − you need to add data-toggle = "tab" or data-toggle = "pill" to the anchors.
Adding the nav and nav-tabs classes to the tab ul will apply the Bootstrap
, while adding the nav and nav-pills classes will apply .<ul class = "nav nav-tabs"> <p><a href = "#identifier" data-toggle = "tab">Home</a></p> ... </ul>
Via JavaScript − you can enable tabs using Javscript as below −
$( #myTab a ).cpck(function (e) { e.preventDefault() $(this).tab( show ) })
Here’s an example of different ways to activate inspanidual tabs −
// Select tab by name $( #myTab a[href = "#profile"] ).tab( show ) // Select first tab $( #myTab a:first ).tab( show ) // Select last tab $( #myTab a:last ).tab( show ) // Select third tab (0-indexed) $( #myTab p:eq(2) a ).tab( show )
Fade Effect
To get a fade effect for tabs, add .fade to each .tab-pane. The first tab pane must also have .in to properly fade in initial content −
<span class = "tab-content"> <span class = "tab-pane fade in active" id = "home">...</span> <span class = "tab-pane fade" id = "svn">...</span> <span class = "tab-pane fade" id = "ios">...</span> <span class = "tab-pane fade" id = "java">...</span> </span>
Example
An example of tab plugin using data attributes and fade effect is as shown in the following example −
<ul id = "myTab" class = "nav nav-tabs"> <p class = "active"> <a href = "#home" data-toggle = "tab"> Tutorial Point Home </a> </p> <p><a href = "#ios" data-toggle = "tab">iOS</a></p> <p class = "dropdown"> <a href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"></b> </a> <ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <p><a href = "#jmeter" tabindex = "-1" data-toggle = "tab">jmeter</a></p> <p><a href = "#ejb" tabindex = "-1" data-toggle = "tab">ejb</a></p> </ul> </p> </ul> <span id = "myTabContent" class = "tab-content"> <span class = "tab-pane fade in active" id = "home"> <p>Tutorials Point is a place for beginners in all technical areas. This website covers most of the latest technologies and explains each of the technology with simple examples.</p> </span> <span class = "tab-pane fade" id = "ios"> <p>iOS is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple TV. iOS is derived from OS X, with which it shares the Darwin foundation. iOS is Apple s mobile version of the OS X operating system used on Apple computers.</p> </span> <span class = "tab-pane fade" id = "jmeter"> <p>jMeter is an Open Source testing software. It is 100% pure Java apppcation for load and performance testing.</p> </span> <span class = "tab-pane fade" id = "ejb"> <p>Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level apppcations to be deployed on J2EE comppant Apppcation Server such as JBOSS, Web Logic etc.</p> </span> </span>
Methods
.$().tab − This method activates a tab element and content container. Tab should have either a data-target or an href targeting a container node in the DOM.
<ul class = "nav nav-tabs" id = "myTab"> <p class = "active"><a href = "#identifier" data-toggle = "tab">Home</a></p> ..... </ul> <span class = "tab-content"> <span class = "tab-pane active" id = "home">...</span> ..... </span> <script> $(function () { $( #myTab a:last ).tab( show ) }) </script>
Example
The following example shows the use of tab plugin method .tab. Here in the example the second tab iOS is activated −
<ul id = "myTab" class = "nav nav-tabs"> <p class = "active"> <a href = "#home" data-toggle = "tab"> Tutorial Point Home </a> </p> <p><a href = "#ios" data-toggle = "tab">iOS</a></p> <p class = "dropdown"> <a href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"></b> </a> <ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <p> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab"> jmeter </a> </p> <p> <a href = "#ejb" tabindex = "-1" data-toggle = "tab"> ejb </a> </p> </ul> </p> </ul> <span id = "myTabContent" class = "tab-content"> <span class = "tab-pane fade in active" id = "home"> <p>Tutorials Point is a place for beginners in all technical areas. This website covers most of the latest technologies and explains each of the technology with simple examples.</p> </span> <span class = "tab-pane fade" id = "ios"> <p>iOS is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple TV. iOS is derived from OS X, with which it shares the Darwin foundation. iOS is Apple s mobile version of the OS X operating system used on Apple computers.</p> </span> <span class = "tab-pane fade" id = "jmeter"> <p>jMeter is an Open Source testing software. It is 100% pure Java apppcation for load and performance testing.</p> </span> <span class = "tab-pane fade" id = "ejb"> <p>Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level apppcations to be deployed on J2EE comppant Apppcation Server such as JBOSS, Web Logic etc.</p> </span> </span> <script> $(function () { $( #myTab p:eq(1) a ).tab( show ); }); </script>
Events
Following table psts the events to work with tab plugin. This event may be used to hook into the function.
Event | Description | Example |
---|---|---|
show.bs.tab | This event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
$( a[data-toggle = "tab"] ).on( show.bs.tab , function (e) { e.target // activated tab e.relatedTarget // previous tab }) |
shown.bs.tab | This event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
$( a[data-toggle = "tab"] ).on( shown.bs.tab , function (e) { e.target // activated tab e.relatedTarget // previous tab }) |
Example
The following example shows use of tab plugin events. Here in the example we will display the current and previous visited tabs −
<hr> <p class = "active-tab"><strong>Active Tab</strong>: <span></span></p> <p class = "previous-tab"><strong>Previous Tab</strong>: <span></span></p> <hr> <ul id = "myTab" class = "nav nav-tabs"> <p class = "active"> <a href = "#home" data-toggle = "tab"> Tutorial Point Home </a> </p> <p><a href = "#ios" data-toggle = "tab">iOS</a></p> <p class = "dropdown"> <a href = "#" id = "myTabDrop1" class = "dropdown-toggle" data-toggle = "dropdown"> Java <b class = "caret"></b> </a> <ul class = "dropdown-menu" role = "menu" aria-labelledby = "myTabDrop1"> <p> <a href = "#jmeter" tabindex = "-1" data-toggle = "tab">jmeter</a> </p> <p> <a href = "#ejb" tabindex = "-1" data-toggle = "tab">ejb</a> </p> </ul> </p> </ul> <span id = "myTabContent" class = "tab-content"> <span class = "tab-pane fade in active" id = "home"> <p>Tutorials Point is a place for beginners in all technical areas. This website covers most of the latest technologies and explains each of the technology with simple examples.</p> </span> <span class = "tab-pane fade" id = "ios"> <p>iOS is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple TV. iOS is derived from OS X, with which it shares the Darwin foundation. iOS is Apple s mobile version of the OS X operating system used on Apple computers.</p> </span> <span class = "tab-pane fade" id = "jmeter"> <p>jMeter is an Open Source testing software. It is 100% pure Java apppcation for load and performance testing.</p> </span> <span class = "tab-pane fade" id = "ejb"> <p>Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level apppcations to be deployed on J2EE comppant Apppcation Server such as JBOSS, Web Logic etc.</p> </span> </span> <script> $(function(){ $( a[data-toggle = "tab"] ).on( shown.bs.tab , function (e) { // Get the name of active tab var activeTab = $(e.target).text(); // Get the name of previous tab var previousTab = $(e.relatedTarget).text(); $(".active-tab span").html(activeTab); $(".previous-tab span").html(previousTab); }); }); </script>Advertisements