Live Demo
Click between the tabs below - this is a real, working tabs() widget. The button jumps to Tab 3 programmatically via the active option.
The jQuery UI tabs() widget turns a list of links and their matching content panels into a classic tabbed interface - only the active tab's panel is visible, and clicking another tab (or link) swaps which panel shows, without a full page reload.
<!-- markup: a <ul> of links to #fragment ids, each matched by a panel with that id -->
<div id="tabs">
<ul>
<li><a href="#tab-1">Tab 1</a></li>
<li><a href="#tab-2">Tab 2</a></li>
</ul>
<div id="tab-1"><p>First panel content.</p></div>
<div id="tab-2"><p>Second panel content.</p></div>
</div>
$('#tabs').tabs(); // jQuery UI wires the click handlers and toggles panels
active option
// pick which tab (zero-based index) is open when the widget is created
$('#tabs').tabs({
active: 1 // opens "Tab 2" by default
});
// switch tabs programmatically at any time, e.g. from a button click
$('#tabs').tabs('option', 'active', 2);
activate event
$('#tabs').tabs({
activate: function(event, ui){
// ui.newTab / ui.newPanel = the tab & panel that just became active
// ui.oldTab / ui.oldPanel = the tab & panel that just lost focus
console.log(ui.newTab.text());
}
});
// give a tab's <a> a real URL instead of a "#fragment" and jQuery UI will
// fetch that URL over AJAX and drop the response into the tab panel
<li><a href="remote-content.php">Remote Tab</a></li>
$('#tabs').tabs(); // no extra config needed - detected automatically from the href
href at an endpoint that returns an HTML fragment.Click between the tabs below - this is a real, working tabs() widget. The button jumps to Tab 3 programmatically via the active option.