Igor R Igor
Igor R Igor

Reputation: 1

No such method 'length' for tabs widget instance

I get an error

no such method 'length' for tabs widget instance

How do I get the current number of tab?

I am using the jQuery libary version 10.3 that is download from the site http://jqueryui.com/

    $(document).ready(function(){
    $("#tabs").tabs();

    $("#prevBtn").bind("click", prevOfferTab);
    $("#nextBtn").bind("click", nextOfferTab);
});

function getSelectedTabIndex(change)  {
    var $tabs = $('#tabs').tabs();
    var selected = $tabs.tabs('option', 'selected') + change;

    if (selected == 0) {
    $("#prevBtn").hide();
    }
    else {
    $("#prevBtn").show();
    }

    var tabsCount = this.$('#tabs').tabs('length') -1;
    if (selected == tabsCount) {
    $("#nextBtn").hide();
    }
    else {
    $("#nextBtn").show();
    }

    return selected;
}

    enter code here

function nextOfferTab()  {
    console.log('nxt');
    var newTabIndex = parseInt(getSelectedTabIndex(1));
    $('#tabs').tabs('select', newTabIndex);
}

function prevOfferTab()  {
    var newTabIndex = parseInt(getSelectedTabIndex(-1));
    $('#tabs').tabs('select', newTabIndex);
}

Upvotes: 0

Views: 2701

Answers (1)

augusto1405
augusto1405

Reputation: 11

var tabsCount = $("#tabs >ul >li").size();

Upvotes: 1

Related Questions