Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need currently selected tab ID for jQuery tabs

Tags:

I know I can get the index of the currently selected tab but can I somehow get to the ID (the equivalent of the ui.panel.id if this were triggered by an tab event...but it's not) of the currently selected tab? I'd prefer not to use the index because ordering of the tabs might change. I prefer not to use the style markups as those may change in future releases. Is there a method for this? If not, can I somehow use the index to access this (maybe even by accessing the panel object first)? Any other ideas?

like image 734
ejf Avatar asked Dec 08 '09 02:12

ejf


People also ask

How do I know which tab is selected in jQuery?

var selectedTab = $("#TabList"). tabs(). data("selected. tabs");

How do you keep the current tab active on page reload?

Answer: Use the HTML5 localStorage Object In Bootstrap, if you refresh the page the tab is reset to default setting. However, you can use the HTML5 localStorage object to save some parameter for the current tab locally in the browser and get it back to make the last active tab selected on page reload.


1 Answers

You can use the :visible pseudo-selector to target the visible panel:

$("#tabs .ui-tabs-panel:visible").attr("id");

It's worth noting that you can retrieve the active tab from the activate event:

$("#tabs").tabs({
    activate: function (event, ui) {
        console.log(ui.newPanel[0].id);
    }
});
like image 65
Sampson Avatar answered Sep 18 '22 13:09

Sampson