Tabs with two levels of jquery

I need to have two-level tab navigation.

Mostly like this:

Tab1 Tab2 Tab3

TabA TabB TabC

When the user presses, for example, Tab2, he can again select the second level tab (TabA, TabB, etc.).

I can do the first level normally, but I can not do the 2nd level. How can I put it on the first level tabs.

+5
source share
1 answer

Just insert the second set of tabs into the first set inside your html, for example:

<div id="tabs">
    <ul>
        <li><a href="#tab-1"><span>One</span></a></li>
        <li><a href="#tab-2"><span>Two</span></a></li>
        <li><a href="#tab-3"><span>Three</span></a></li>
    </ul>
    <div id="tab-1">
      <p>First tab is active by default.</p>
      <p>Second tab contains nested tabs.</p>
    </div>
    <div id="tab-2">
      <!-- Nested Tabs! -->
      <ul>
        <li><a href="#nested-1"><span>One</span></a></li>
        <li><a href="#nested-2"><span>Two</span></a></li>
        <li><a href="#nested-3"><span>Three</span></a></li>
      </ul>
      <div id="nested-1">
        Nest tab 1 content: Onerem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy..
      </div>
      <div id="nested-2">
        Nest tab 2 content: Tworem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy..
      </div>
      <div id="nested-3">
        Nest tab 3 content: Threm ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy..
      </div>
      <!-- End Nested Tabs -->
      Regular tab 2 content (optional)
    </div>
    <div id="tab-3">
        <p>Second tab contains multiple tabs.</p>
    </div>
</div>

.. and initialize them as on the finished document like this:

<script>
  $(document).ready(function() {
    $("#tabs").tabs();
    $("#tab-2").tabs();
  });
</script>

If in doubt, check out the jQuery tabs api documentation at http://docs.jquery.com/UI/Tabs

+5
source

All Articles