omega
omega

Reputation: 43833

How to get currently selected tab index in jquery UI?

In jquery UI, using their newest version, I can't get the ID of the selected tab anymore. I tried ui.index from jQuery UI Tabs Get Currently Selected Tab Index, but it gives me undefined.

Does anyone know the way to do this now?

$( "#tabs" ).bind( "tabsactivate", function(event, ui) { 
    alert(ui.index);
});

In this code, I get the alert every time I select a new tab, but its says undefined.

Thanks

Upvotes: 2

Views: 15551

Answers (1)

PSL
PSL

Reputation: 123739

You need to use it this way. ui does not have any property called index

alert(ui.newTab.index());

Demo

  1. Get the index of currently selected tab: ui.newTab.index()
  2. Get the index of last selected tab: ui.oldTab.index()

ui.newTab will return you the jquery object representing the element and you can invoke the index() method on it to get the index.

Upvotes: 15

Related Questions