...

View Full Version : [JQUERY] Tabs: show back the default content after load()



hernantz
10-23-2010, 09:26 PM
Hi all,
Cant figure out how to do this. When the page loads, there is a default tab selected (the first one) and some content displayed. The other tabs load external content, and its al working except when i click again the first (and default) tab.

HTML code


<div id="TabsBar">
<a href="#">Tab1</a>
<a href="external1.html">Tab2</a>
<a href="external2.html">Tab3</a>
<a href="external3.html">Tab4</a>
</div>

<div id="TabContent">Here is the default content :D</div>


Jquery code



$(document).ready(function() {
//Assign "selected" class to the first tab.
$("#TabsBar a:first").addClass("selected");

//Switch tabs when clicked.
$("#TabsBar a").click(switch_tabs);


//Declare switch tabs function.
function switch_tabs(){
//Remove the "selected class" and assign it to the current tab.
$("#TabsBar a").removeClass("selected");
$(this).addClass("selected");
//Get the link value.
var page=$(this).attr("href");
//This is the div where the content goes.
var x=$("#TabContent");

//Check and show the default content or an external one.
if(page=="#"){

//HERE I SHOULD SHOW THE DEFAULT TAB'S CONTENT

}
else{
x.load(page);
return false;
}
}

});


Any idea is welcome, thanks in advance



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum