Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI dynamic tab - Auto select

I was trying to add a dynamic tab on a button click. I successfully completed it. Now I want my dynamic tab to be selected automatically when its created.

This is My code:

$(document).ready(function(){

    var tabs = $("#container-1").tabs();
    $('#add_tab').click( function(){
            var ul = tabs.find( "ul" );
            $( "<li><a href='#newtab'>New Tab</a></li>" ).appendTo( ul );
            $( "<div id='newtab'>Name :<input type='text'></input></div>" ).appendTo( tabs );
            tabs.tabs( "refresh" );
            tabs.tabs("select", 1);
        });
});

I use CDN links in the order:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>

The problem is that my dynamic tab is not getting selected automatically

The error I get is:

Error: no such method 'select' for tabs widget instance
http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
Line 2

How do i fix this?

NOTE: my code is working in jsfiddle:http://jsfiddle.net/StDbH/

But not on my system: Fedora 16 + Firefox 18.0.1

like image 434
Okky Avatar asked Jan 29 '13 05:01

Okky


2 Answers

add this line after refresh:

tabs.tabs( "option", "active", -1 );

http://jsfiddle.net/StDbH/1/

like image 103
Vic Avatar answered Oct 12 '22 01:10

Vic


try show() options of tab

$( ".selector" ).tabs({ show: { effect: "blind", duration: 800 } });    
like image 27
bipen Avatar answered Oct 12 '22 02:10

bipen