Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI tabs loading first as <ul> then as tabs

Tags:

jquery-ui

I'm using jQuery UI and the tab control on a series of pages. It seems like, when loading a page, the tabs initially load as a simple list, then they jump to the tabstrip.

When I initially load the page I get this: alt text

Then, after a few seconds it switches over to this (the way is should be): alt text

Any idea why this is happening? Do I need to load the .js and/or .css files in a particular order? Or, is there a way to hide the initial list and only display the tabs once they are 'loaded'?

like image 251
Jason Avatar asked Oct 02 '09 01:10

Jason


People also ask

How do I make the first tab active in jquery?

removeClass('ep_s-click1'). addClass('ep_s1'); }} } }); if i use selected: 0 it will set up the first tab as active but it will now go through the if (theSelectedTab2 == 0) statement and go through adding those classes. if after the page loads i click on those tabs the script works perfect.

How do I go to a specific tab in jquery?

tabs(); $('. benefitc'). click(function () { // bind click event to link $tabs. tabs('select', 4); // switch to tab return false; });


1 Answers

This happens because you call $('#id').tabs() in document.ready(), which happens when the DOM is ready to be traversed[1]. This generally means the page has been rendered, and so the <ul> is visible on the page as a regular <ul> without any tab-specific styling applied.

It's not super "clean", but a way I use to get around this is to add the ui-tabs class to the <ul> in the HTML, which causes it to get the CSS style applied immediately. The downside is that you don't have the 100% clean separation of behaviour and code, but the upside is it looks nice.

like image 80
gregmac Avatar answered Sep 23 '22 12:09

gregmac