Skip to content

Instantly share code, notes, and snippets.

@phawk
Created January 15, 2012 12:12
Show Gist options
  • Save phawk/1615663 to your computer and use it in GitHub Desktop.
Save phawk/1615663 to your computer and use it in GitHub Desktop.
// Runs this function when the page loads
$(document).ready(structureTabs);
function structureTabs()
{
// Insert a list to hold the tab buttons
$('#tabs').prepend('<ul id="tabbtns"></ul>');
// Split the content up, starting with each h2 and all other content until the following h2 comes.
$('#tabs h2').each(function(index){
$(this).nextUntil('h2').andSelf().wrapAll('<div id="tabs-'+(index+1)+'"></div>');
var title = $(this).text();
$('#tabbtns').append('<li><a href="#tabs-' + (index+1) + '">' + title + '</a></li>');
});
// Remove the h2 headings.
$('#tabs div h2').remove();
}
jQuery(function() {
jQuery("#tabs").tabs();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment