How to Get Currently Selected Tab Index In jQuery UI Tabs

0 votes

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. Am I doing something wrong here?

Sep 10, 2020 in JQuery by kartik
• 37,510 points
17,381 views

1 answer to this question.

0 votes

Hello @kartik,

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')

Hope it helps!!
Thank you!!

answered Sep 10, 2020 by Niroj
• 82,880 points

Related Questions In JQuery

0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello @kartik, Use data option of ajax. You ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,880 points
6,445 views
0 votes
1 answer

How to import jQuery UI using ES6/ES7 syntax?

Hii, Add a alias in webpack config: resolve: { ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
7,426 views
0 votes
1 answer

How to remove close button on the jQuery UI dialog?

Hii, I found this worked for me in the end ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
4,354 views
0 votes
1 answer

How to set cache false for getJSON in jQuery?

Hello @kartik, Your code just needs a trigger ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
718 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
22,476 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
2,990 views
0 votes
1 answer

How to enable Bootstrap tooltip on disabled button?

Hii @kartik, You can wrap the disabled button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
4,688 views
+1 vote
2 answers

How to set cache false for getJSON in jQuery?

You can't pass any configuration parameters to ...READ MORE

answered Oct 7, 2020 in JQuery by Amit
• 140 points
2,515 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
41,846 views
0 votes
1 answer

How to prevent multiple selection in jQuery UI Selectable plugin?

Hii @kartik, What I did is that I allow multiple ...READ MORE

answered May 30, 2020 in JQuery by Niroj
• 82,880 points
969 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP