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

后端 未结 6 544
温柔的废话
温柔的废话 2021-01-19 23:06

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 tr

相关标签:
6条回答
  • 2021-01-19 23:46

    Use following in case of jQuery 1.9+,

    var currentTabTitle = $('div[id="mytabs"] ul .ui-tabs-active > a').attr("href");
    
    0 讨论(0)
  • 2021-01-19 23:55

    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());
    });
    
    0 讨论(0)
  • 2021-01-20 00:01

    Just another version:

    $("#tabsId .ui-state-active > a").html()
    
    0 讨论(0)
  • 2021-01-20 00:04

    Alternative way to get tab title:

    var selected = $("#tabs").tabs( "option", "selected" );
    var selectedTabTitle = $($("#tabs li")[selected]).text();
    
    0 讨论(0)
  • 2021-01-20 00:10

    From the jquery docs,

    var selectedTabTitle = null;
    $( ".selector" ).tabs({
       select: function(event, ui) {
                selectedTabTitle = $(ui.tab).text();
                alert(selectedTabTitle);
        }
    });
    
    0 讨论(0)
  • 2021-01-20 00:10

    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 讨论(0)
提交回复
热议问题