How can I go to a specific tab after a click event using jquery?

How can I go to a specific tab after a click event, I tried $("#tabs").tabs() since every time I refresh it go back to its original but still does not work, what is the right way of doing it?

Here's my jquery code:

$(function() {
    $("#tabs").tabs();
    $("#btn").click(function() {
    //what to put here?
    //I tried this but do not work, since i notice every refresh it go back to its original tab
    $("#tabs").tabs();
    });
});

Here's my HTML Code:

<div id="tabs">
<ul>
<li><a href="#login">Login</a></li>
<li><a href="#register">Register</a></li>
</ul>
<div id="login">
</div>
<div id="register">
</div>

Answers


You can use the select method of jquery ui tabs:

$(function() {
    $("#tabs").tabs();
    $("#btn").click(function() {
        $("#tabs").tabs("select", "mytab"); // will switch to mytab
    });
});

give this a try : $('#tabs').triggerTab(2);//2 here is the register tab


Initialize a tabs with the selected option specified.

$( ".selector" ).tabs({ selected: 3 });

Get or set the selected option, after init.

//getter
var selected = $( ".selector" ).tabs( "option", "selected" );
//setter
$( ".selector" ).tabs( "option", "selected", 3 );

You can store the latest tab in a Cookie without too much extra code:

http://jqueryui.com/demos/tabs/#option-cookie

$( ".selector" ).tabs({ cookie: { expires: 30 } });

It'll always then return to the last tab you were on.

Then to go to a specific tab: http://jqueryui.com/demos/tabs/#option-selected

$( ".selector" ).tabs( "option", "selected", 3 );

Need Your Help

Can InDesign CS5 do automatic pagination while import XML data?

xml import flash-cs5 indesign

I have googled a lot about pagination of importing XML data into InDesign CS5, but problems are still unsolved.

Update pinned PFObject in Parse Local Storage from Parse Cloud

ios xcode swift parse.com

By object.saveEventually(), I will be able to sync my data in local storage with the cloud in Parse.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.