JQuery UI Dynamic Tab - Auto Selection

I tried to add a dynamic tab with a click of a button. I successfully completed it. Now I want my dynamic tab to be automatically selected when it is 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 following 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 automatically selected

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 to fix it?

NOTE: my code works in jsfiddle: http://jsfiddle.net/StDbH/

But not on my system: Fedora 16 + Firefox 18.0.1

+5
source share
2 answers

add this line after update:

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

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

+9
source

()

$( ".selector" ).tabs({ show: { effect: "blind", duration: 800 } });    
+1

All Articles