Tabs are generally used to break content into multiple sections that can be swapped to save space, much like an accordion. By default a tab widget will swap between tabbed sections onClick, but the events can be changed to onHover through an option. Tab content can be loaded via Ajax by setting an href on a tab.
How to create Tabs?
1. Initialize the plugin
jQuery(function() {
jQuery(" .ui_tabs ").tabs();
});2. Create the HTML using the same class used in the code above:
<div class="ui_tabs"> ... </div>
2.1 Create tabs list:
<div class="ui_tabs"> <ul> <li><a href="#tabs-1">Tabs 1</a></li> <li><a href="#tabs-2">Tab 2</a></li> <li><a href="#tabs-3">Tab 3</a></li> </ul> </div>
2.2 Create tabs sections using as ID the same text from tabs list, href="" attribute:
<divclass="ui_tabs"> <ul> <li><a href="#tabs-1">Tabs 1</a></li> <li><a href="#tabs-2">Tab 2</a></li> <li><a href="#tabs-3">Tab 3</a></li> </ul> <divid="tabs-1"> <p> THIS IS THE TEXT FOR FIRST TAB</p> </div> <divid="tabs-2"> <p> THIS IS THE TEXT FOR SECOND TAB</p> </div> <divid="tabs-3"> <p> THIS IS THE TEXT FOR THIRD TAB</p> </div> </div>
This has a little different structure. The main goal is to create a "tab-ified box".
1. Initialize the plugin
jQuery(function() {
jQuery( ".ui_tabs_right" ).tabs();
});2. Create a box with class "ui_tabs_right":
<section class="grid_12">
<div class="box ui_tabs_right">
<div class="title"> Tabs aligned to right </div>
<div class="inside">
<div class="in">
CONTENT TO BE HERE...
</div>
</div>
</div>
</section>3. Create tab navigation. You must include it inside of box title:
<section class="grid_12"> <div class="box ui_tabs_right"> <div class="title"> Tabs aligned to right<ul><li><a href="#tabs-1a">Tab 1</a></li><li><a href="#tabs-2a">Tab 2</a></li><li><a href="#tabs-3a">Tab 3</a></li></ul></div> <div class="inside"> <div class="in"> CONTENT TO BE HERE... </div> </div> </div> </section>
4. Create tabs sections using as ID the same text from tabs list, href="" attribute:
<section class="grid_12"> <div class="boxui_tabs_right"> <div class="title"><span class="icon16_sprite i_abacus"></span><!-- Additional box icon ;) --> Tabs aligned to right <ul> <li><a href="#tabs-1a">Tab 1</a></li> <li><a href="#tabs-2a">Tab 2</a></li> <li><a href="#tabs-3a">Tab 3</a></li> </ul> </div> <div class="inside"> <div class="in"> <div id="tabs-1a"> <div class="grid_12"> <p>Tabs section 1 content</p> </div> </div> <div id="tabs-2a"> <div class="grid_12"> <p>Tabs section 2 content</p> </div> </div> <div id="tabs-3a"> <div class="grid_12"> <p>Tabs section 3 content</p> </div> </div> </div> </div> </div> </section>
| OPTION | TYPE | DEFAULT | DESCRIPTION |
|---|---|---|---|
disabled | Boolean | false |
Disables (true) or enables (false) the tabs. Can be set when initialising (first creating) the tabs. |
ajaxOptions | Options | null |
Additional Ajax options to consider when loading tab content (see $.ajax). |
cache | Boolean | false |
Whether or not to cache remote tabs content, e.g. load only once or with every click. Cached content is being lazy loaded, e.g once and only once for the first click. Note that to prevent the actual Ajax requests from being cached by the browser you need to provide an extra cache: false flag to ajaxOptions. |
collapsible | Boolean | false |
Set to true to allow an already selected tab to become unselected again upon reselection. |
cookie | Object | null |
Store the latest selected tab in a cookie. The cookie is then used to determine the initially selected tab if the selected option is not defined. Requires cookie plugin, which can also be found in the development-bundle>external folder from the download builder. The object needs to have key/value pairs of the form the cookie plugin expects as options. Available options (example): { expires: 7, path: '/', domain: 'jquery.com', secure: true }. Since jQuery UI 1.7 it is also possible to define the cookie name being used via name property. |
disabled | Array | [] |
An array containing the position of the tabs (zero-based index) that should be disabled on initialization. |
event | String | click |
The type of event to be used for selecting a tab. |
fx | Options, Array | null |
Enable animations for hiding and showing tab panels. The duration option can be a string representing one of the three predefined speeds ("slow", "normal", "fast") or the duration in milliseconds to run an animation (default is "normal"). |
idPrefix | String | 'ui-tabs-' |
If the remote tab, its anchor element that is, has no title attribute to generate an id from, an id/fragment identifier is created from this prefix and a unique id returned by $.data(el), for example "ui-tabs-54". |
panelTemplate | String | '<div></div>' |
HTML template from which a new tab panel is created in case of adding a tab with the add method or when creating a panel for a remote tab on the fly. |
selected | Number | 0 |
Zero-based index of the tab to be selected on initialization. To set all tabs to unselected pass -1 as value. |
spinner | String | '<em>Loading…</em>' |
The HTML content of this string is shown in a tab title while remote content is loading. Pass in empty string to deactivate that behavior. An span element must be present in the A tag of the title, for the spinner content to be visible. |
tabTemplate | String | '<li><a href="#{href}"><span>#{label}</span></a></li>' |
HTML template from which a new tab is created and added. The placeholders #{href} and #{label} are replaced with the url and tab label that are passed as arguments to the add method. |
| OPTION | TYPE | DEFAULT | DESCRIPTION |