4
votes

I'm using http://jqueryui.com/demos/tabs/#manipulation. I want to get an title of current selected tab which I earlier named (e.g. from a href). How to get it?

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

6

6 Answers

7
votes

From the jquery docs,

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

Alternative way to get tab title:

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

Use following in case of jQuery 1.9+,

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

Just another version:

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

i guess jquery was modified because now i was able to fetch tab name using:

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

Thanks I was struggling with this code.

Now I've used thiscode in my program. Working like this.

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