Klaus Hartl schrieb:
Here we go:

jQuery.fn.selectedTab = function() {
    var selectedTabs = [];
    this.each(function() {
        var nav = jQuery('ul.tabs-nav' , this);
nav = nav.size() && nav || jQuery('>ul:eq(0)', this); // fallback to default structure
        var lis = jQuery('li', nav);
selectedTabs.push(lis.index( lis.filter('.tabs-selected')[0] ) + 1);
    });
    return selectedTabs.length > 1 ? selectedTabs : selectedTabs[0];
};

It returns a number if you check for one tab interface

$('#container').selectedTab(); // => 1

and an array if you check for multiple interfaces:

$('#container-1, #container-2').selectedTab(); // => [1, 1]

As usual for the plugin it is not a zero-based index. Thus you can do:

var tabs = $('#container-1');
tabs.disableTab(tabs.selectedTab());


And it re

Ups.

And it returns 0 if there's no selected tab (which shouldn't be the case the way the tabs work). But it could be exploited to check for existance of tabs:

if ( $('#whatever').selectedTab() ) {

    // yes, there are tabs...

}

Hm, not very useful probably.


-- Klaus

Reply via email to