HTML Tabs have became one of the most used UI components in web design. Tabs are generally used to break content into multiple sections that can be swapped to save space. Different implementation of HTML Tabs are available and jQuery UI is one of the simplest one.
For adding jQuery tabs in your HTML page, first you have to make sure that you included the theme css file properly in html. If themes css is not set properly, jQuery tabs will not be rendered properly. Next, include the jQuery javascript in your HTML page. And create your HTML file which contains the tab code.
Create your tabs by adding following unordered list in the DIV.
< ul > < li >< a href = "#firstTab" >First</ a ></ li > < li >< a href = "#secondTab" >Second</ a ></ li > < li >< a href = "#thirdTab" >Third</ a ></ li > < li >< a href = "#forthTab" >Forth</ a ></ li > </ ul > |
< div id = "firstTab" >first content</ div > < div id = "secondTab" >second content</ div > < div id = "thirdTab" >Third content</ div > < div id = "forthTab" >Forth content</ div > |
$(document).ready( function () { $( "#tabs" ).tabs(); }); |
Tab Events in jQuery
A series of events fire when interacting with a tabs interface:* tabsselect, tabsload, tabsshow (in that order)
* tabsadd, tabsremove
* tabsenable, tabsdisable
$( '#tabs' ).bind( 'tabsselect' , function (event, ui) { // Objects available in the function context: alert(ui.tab); // anchor element of the selected (clicked) tab alert(ui.panel); // element, that contains the selected/clicked tab contents alert(ui.index); // zero-based index of the selected (clicked) tab }); |
Lazy loading tab using AJAX
Tabs supports loading tab content via Ajax in an unobtrusive manner.The HTML you need is slightly different from the one that is used for static tabs: A list of links pointing to existing resources (from where the content gets loaded) and no additional containers at all (unobtrusive!). The containers’ markup is going to be created on the fly:
< div id = "example" > < ul > < li >< a href = "sample_1.html" >< span >Content 1</ span ></ a ></ li > < li >< a href = "sample_2.html" >< span >Content 2</ span ></ a ></ li > < li >< a href = "sample_3.html" >< span >Content 3</ span ></ a ></ li > </ ul > </ div > |