Open first sub tab by default
I'm having a very hard time with this.
I'm trying to make nested tabs that can later be used with AJAX. Everything seems to work but this:
If you click Main Tab B, then Subtab 2
Then click Main Tab A, and go back to Main Tab B - Subtab 2 is still open.
I need the default sub tab for each main tab to be the first one.
IMPORTANT : I'm almost 100% positive that the problem lies in this line of code in the subTabs function.
- <!DOCTYPE html>
- <html>
- <head>
-
- <title>Subtabs & Ajax</title>
-
- <script src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script>
- <link rel="stylesheet" type="text/css" href="styles.css" />
-
- </head>
- <body>
- <div style="width: 100%; text-align: center;">
- <div class="wrap">
-
- <!-- Parent Tabs -->
- <ul id="mainTabs" class="tabs" style="border-style: none;">
- <li><a href="#pageA1">Main A</a></li>
- <li><a href="#pageB1">Main B</a></li>
- </ul>
- <div style="height: 11px;"></div>
-
- <!-- Subtabs -->
-
- <div class="pane">
- <p>Main A</p>
-
- <ul id="subTabs" class="tabs">
- <li><a href="#pageA1">Subtab 1</a></li>
- <li><a href="#pageA2">Subtab 2</a></li>
- </ul>
-
-
- <div class="pane">
- <h3>First Tab Content </h3 ><br>
- <div class="initTab" class="content" style="width:400px; height: 400px; background-color: #CCC;"></div>
- </div>
-
- <div class="pane">
- <h3>Second tab content</h3 ><br>
- <div class="content" style="width:400px; height: 400px; background-color: #CCC;"></div>
- </div>
- </div>
-
- <div class="pane">
- <p>Main B</p>
-
- <ul id="subTabs" class="tabs">
- <li><a href="#pageB1">Subtab 1</a></li>
- <li><a href="#pageB2">Subtab 2</a></li>
- </ul>
-
- <div class="pane"><h3>First tab content.</h3 ><br>
- <div class="content" style="width:400px; height: 400px; background-color: #CCC;">
- </div>
- </div>
-
- <div class="pane"><h3>Second tab content</h3 > <br>
- <div class="content" style="width:400px; height: 400px; background-color: #CCC;">
- </div>
- </div>
- </div>
-
- <br>
-
- </div> </div>
- </div>
-
- <script>
- // perform JavaScript after the document is scriptable.
- $(document).ready(function(){
- $(".initTab").load("pageA1.txt"); //Load ajax for initial tab when site first opens
- subTabs(); //Load subtabs when main tab is clicked
- loadAjax(); //Load ajax content when sub tab is clicked
-
- });
-
- function subTabs(){ //Subtab page area
- $("ul.tabs").tabs("> .pane");
- }
- function loadAjax(){
- $(".tabs a").click(function(){
- var page = this.hash.substring(1); //Remove Hash from href
- $(".content").load(page+".txt"); //Load .txt file corresponding to href
- });
-
- }
-
- </script>
-
- </body>
- </html>