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
beetle
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
user405398
source
to share
An alternative way to get the tab title:
var selected = $("#tabs").tabs( "option", "selected" );
var selectedTabTitle = $($("#tabs li")[selected]).text();
+16
Gerson Beltrรกn
source
to share
Use in case jQuery 1.9+,
var currentTabTitle = $('div[id="mytabs"] ul .ui-tabs-active > a').attr("href");
+4
Santosh
source
to share
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
ufk
source
to share
Another version:
$("#tabsId .ui-state-active > a").html()
+2
MCurbelo
source
to share
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
user5572350
source
to share