Query UI Tabs: Changing selected tab | Remembering Active Tab in JQuery UI Tabs | Select last tab by default on Page load, jQuery Ui Tabs | how to set a tab active in jQuery ui tab on page load | Set Jquery ui active tab on page load/reload
I'm using a basic implementation of Jquery UI Tabs that are working fine but I want to set (or reset) the active tab dynamically based on a user action.
You can manually active a tab using below code (2 is index of tab):
$("#tabs").tabs("option", "active", 2);
I'm using a basic implementation of Jquery UI Tabs that are working fine but I want to set (or reset) the active tab dynamically based on a user action.
<div id="tabs"> <ul> <li><a href="#tabs-1">Tab 1</a></li> <li><a href="#tabs-2">Tab 2</a></li> <li><a href="#tabs-3">Tab 3</a></li> </ul> <div id="tabs-1"> First tab </div> <div id="tabs-2"> Second tab </div> <div id="tabs-3"> Third tab </div> </div> <div class='log'></div>
$(function ($) { $("#tabs").tabs({ active: 1, create: function (event, ui) { var newIndex = ui.tab.parent().children().index(ui.tab); $(".log").prepend("<div>Created fired for child=" + newIndex + "</div>"); }, activate: function (event, ui) { // Get future value var newIndex = ui.newTab.parent().children().index(ui.newTab); $(".log").prepend("<div>Activate fired for child=" + newIndex + "</div>"); }, beforeActivate: function (event, ui) { var newIndex = ui.newTab.parent().children().index(ui.newTab); $(".log").prepend("<div>Before activate fired for child=" + newIndex + "</div>"); } }); });
You can manually active a tab using below code (2 is index of tab):
$("#tabs").tabs("option", "active", 2);