Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    29
    Thanked 1 Time in 1 Post

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

    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
    PHP 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

    PHP 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
    Last edited by hernantz; 10-23-2010 at 09:30 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •