How to get the current tab title which I named in the JQuery Tabs UI

I am using http://jqueryui.com/demos/tabs/#manipulation . I want to get the title of the currently selected tab that I named earlier (from href for example). How do I get it?

I tried: $(ui.tab).attr('href')

+3


source to share


6 answers


From the jQuery docs ,



var selectedTabTitle = null;
$( ".selector" ).tabs({
   select: function(event, ui) {
            selectedTabTitle = $(ui.tab).text();
            alert(selectedTabTitle);
    }
});

      

+8


source


An alternative way to get the tab title:



var selected = $("#tabs").tabs( "option", "selected" );
var selectedTabTitle = $($("#tabs li")[selected]).text();

      

+16


source


Use in case jQuery 1.9+,

var currentTabTitle = $('div[id="mytabs"] ul .ui-tabs-active > a').attr("href");

      

+4


source


I think jquery was changed because now I managed to get the name of the tab using:

$(function () {
 $( "#tabs" ).tabs({
    activate : function (event,ui) {
        selectedTabTitle = ui.newTab[0].innerText;
        alert(selectedTabTitle);
    }
});
});

      

+3


source


Another version:

$("#tabsId .ui-state-active > a").html()

      

+2


source


Thanks, I was struggling with this code.

I have now used this code in my program. Work as follows.

$('#tabs').click('tabsselect', function (event, ui) {
    var selectedTab = $("#tabs").tabs('option','selected');
    alert("selectedTab===>" +  $($("#tabs li")[selectedTab]).text());
});

      

0


source







All Articles