Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Tabs - How to Get Currently Selected Tab Index

I know this specific question has been asked before, but I am not getting any results using the bind() event on the jQuery UI Tabs plugin.

I just need the index of the newly selected tab to perform an action when the tab is clicked. bind() allows me to hook into the select event, but my usual method of getting the currently selected tab does not work. It returns the previously selected tab index, not the new one:

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

Here is the code I am attempting to use to get the currently selected tab:

$("#TabList").bind("tabsselect", function(event, ui) {  }); 

When I use this code, the ui object comes back undefined. From the documentation, this should be the object I'm using to hook into the newly selected index using ui.tab. I have tried this on the initial tabs() call and also on its own. Am I doing something wrong here?

like image 690
Mark Struzinski Avatar asked Nov 18 '08 20:11

Mark Struzinski


People also ask

How do I find the current tab index?

If you want to know tabindex of current element in HTML, then you should use document. activeElement. tabIndex .

How do I know which tab is selected in jquery?

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

How do I check if a tab is active in jquery?

hover(function(event) { if (event. fromElement) { console. log("inactive"); } else { console. log("active"); } });


1 Answers

If you need to get the tab index from outside the context of a tabs event, use this:

function getSelectedTabIndex() {      return $("#TabList").tabs('option', 'selected'); } 

Update: From version 1.9 'selected' is changed to 'active'

$("#TabList").tabs('option', 'active') 
like image 135
Contra Avatar answered Sep 21 '22 14:09

Contra