Skip to content

Instantly share code, notes, and snippets.

@cwaring
Created June 1, 2011 14:11
Show Gist options
  • Save cwaring/1002359 to your computer and use it in GitHub Desktop.
Save cwaring/1002359 to your computer and use it in GitHub Desktop.
jQuery TOC from .section > h2
var items = new Array;
var ul = $('<ul />');
$('.section h2:first-child').each(function(e) {
items.push(this);
});
$.each(items, function(i, item) {
var $item = $(this),
id = $item.attr('id'),
title = $item.text();
ul.append('<li><a href="#' + id + '" title="' + title + '">' + title + '</a></li>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment