简体   繁体   中英

select last tab from a text link in jQuery UI tabs

I'm using jQuery UI tabs for product pages on my website. On some pages I have 2 tabs and on some 3. I would like to open last tab from a text link. The jquery tabs api just shows you how to go a particular tab if you know the tab index(let's say 2 to open 3rd tab). I tried the code below but it didn't help. Please advise. Thanks.

    $("#productTabs").tabs();
    var $tabs = $('#productTabs').tabs(); // first tab selected

    $("a[href$='mylink']").click(function(event){
    $tabs.tabs('select', -1); // switch to last tab
    return false;
    });

Basically get the length of the tab group and subtract one to get the last index value.

$("a[href$='mylink']").click(function(event){
  $tabs.tabs('select', $tabs.tabs.("length") - 1); // switch to last tab
  return false;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM