Created
February 8, 2012 12:02
-
-
Save phawk/1768516 to your computer and use it in GitHub Desktop.
jQuery multiple autotabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| var doc = { | |
| init: function() | |
| { | |
| // Setup first group | |
| doc.structureTabs('#tabs'); | |
| jQuery("#tabs").tabs(); | |
| // Setup second group | |
| doc.structureTabs('#tabs2'); | |
| jQuery("#tabs2").tabs(); | |
| }, | |
| structureTabs: function(elementId) | |
| { | |
| // Insert a list to hold the tab buttons | |
| $(elementId).prepend('<ul class="tabbtns"></ul>'); | |
| // Split the content up, starting with each h2 and all other content until the following h2 comes. | |
| $(elementId+' h2').each(function(index){ | |
| $(this).nextUntil('h2').andSelf().wrapAll('<div id="tabs-'+(index+1)+'"></div>'); | |
| var title = $(this).text(); | |
| $(elementId+' .tabbtns').append('<li><a href="#tabs-' + (index+1) + '">' + title + '</a></li>'); | |
| }); | |
| // Remove the h2 headings. | |
| $(elementId+' div h2').remove(); | |
| } | |
| }; | |
| // Runs this function when the page loads | |
| $(document).ready(doc.init); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment