0

I have some logic which refreshes a portion of my page after I enter some data. The data entry form is on the second tab of a three tab table. When one tab is open the other two are closed.

When I enter the data, the refresh function closes the second tab and opens the first one again, I want the second tab to remain open.

I'm looking for a way of getting the index of the currently open tab which I think will put me on the right path to solving this problem.

So how do I get the index of the currently open tab?

Someone has already asked the same question but I can't seem to get the answer to work for me!

 var index;

 jQuery("#tabs").tabs({
     activate: function (event, ui) {
     index = (ui.newTab.index());
     }
 });
Community
  • 1
  • 1
Daft
  • 10,277
  • 15
  • 63
  • 105
  • Can you post a demo to give us an idea of why it doesn't work? Explain what's going wrong, or what you expect/want that isn't being achieved. Show us your relevant code (HTML, CSS as well as the jQuery). – David Thomas Apr 18 '14 at 14:06
  • Ah, I actually think ui.index is undefined as of jQuery UI 1.9... – Daft Apr 18 '14 at 14:12
  • @Daft: I just tested your code, and it seems to work fine for me. http://jsbin.com/winuwego/1/ – TriniBoy Apr 18 '14 at 15:00

1 Answers1

0

So after some more searching online and some trial and error, I found this works perfectly for me.

 var tab_idx;           

 function getSelectedTabIndex() { 
    return jQuery("#tabs").tabs('option', 'active');
 }

 tab_idx = getSelectedTabIndex();
Daft
  • 10,277
  • 15
  • 63
  • 105