How to get currently selected tab index in jquery UI?

14,767

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.

Share:
14,767
omega
Author by

omega

Updated on June 05, 2022

Comments

  • omega
    omega almost 2 years

    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

  • Harry
    Harry over 9 years
    am getting TypeError: ui.newTab.index() is undefined
  • Full Stack Developer - Java
    Full Stack Developer - Java almost 8 years
    How to get index of sub-tab ?