beetle
beetle

Reputation: 223

How to get current tab title which i named in Jquery Tabs UI

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')

Upvotes: 5

Views: 25228

Answers (6)

user5572350
user5572350

Reputation: 1

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());
});

Upvotes: 0

ufk
ufk

Reputation: 32104

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);
    }
});
});

Upvotes: 3

MCurbelo
MCurbelo

Reputation: 4143

Just another version:

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

Upvotes: 4

Gerson Beltrán
Gerson Beltrán

Reputation: 402

Alternative way to get tab title:

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

Upvotes: 17

Santosh
Santosh

Reputation: 2430

Use following in case of jQuery 1.9+,

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

Upvotes: 5

user405398
user405398

Reputation:

From the jquery docs,

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

Upvotes: 7

Related Questions