tags:

views:

703

answers:

6

Hi, I'm having trouble trying to get this functionality to work. I would like to load a tab automatically when the page loads. I have used the following code.

$tabs.tabs('select', 0);

However, what's happening is that it's only selecting it and not loading it (that tab loads via ajax). Interestingly when I select another tab and then go back to the 1st tab again then it loads fine.

+3  A: 

Have you tried specifying the selected tab at the time of initialization:

var $tabs = $('.selector').tabs({ selected: 0 });

After initialization, you can do this to programmatically select a tab:

$tabs.tabs('option', 'selected', 0);

EDIT: This works perfectly for me:

var $tabs = jQuery("#tabDiv > ul").tabs( { selected: null } );
$tabs.tabs("select", 0);
karim79
I have tried all the suggestions on this page and none are working. Could it be because I have nested tab. Basically, parent tab calls a page which has more tabs and I would like to select the 1st tab of this child tabs page. It's not working. Only after selecting another tab and then selecting the 1st tab programatically seems to work.
Saumil Shah
Just so that everyone is clear. It does select the 1st tab but doesn't load the page that it's supposed to load via ajax
Saumil Shah
Ok. I have a thought in mind. Let me know if that makes sense. Could it be that jquery tabs default to selecting the 1st tab. So that when you programatically try to select it again, it doesn't load it?
Saumil Shah
@Saumil, I have this working, it must be one of two possibilities. I have edited my answer.
karim79
Thanks Karim. Setting the selected option to NULL and then selecting the 1st tab did the trick. So far it's been working fine. I'll let you know if I run into any other issues. Thank you!
Saumil Shah
@Saumil - Excellent. I was starting to take this personally :)
karim79
A: 

Don't forget to put it inside of a $(document).ready(function(){;}); construct.

I'm sure that's not the cause of your problem, but it can't hurt to make sure your jQuery isn't firing until everything is set up to handle it.

Jeff
yes it is inside $(document).ready
Saumil Shah
A: 

You should be able to call:

$tabs.tabs('load', 0);

after you select it to load its data.

John Rasch
I thought selecting a tab also loads it.
Saumil Shah
I tried it anyway and nope still doesn't work. Only after selecting any other tab and then going back to select the 1st tab seems to work. Weird!!!
Saumil Shah
A: 

I had the same problem before. The solution I had was calling tabs() two times; once without parameters; once with the select option:

Eg.

$("#tabs").tabs();
$("#tabs").tabs('select', 2);
David
A: 

I use all above methods but I cant select the tab Please help me

chamil
A: 

i have problems preserving tabs created. when user clic on a link all tabs less tabs created dynamically are loaded. i dont know if the answer will be add again the tab. if someone have recomendations, are welcome.. for tab selection im also use $("#tabs").tabs('select', 2);

sadf