Skip to content

Instantly share code, notes, and snippets.

@metamn
Created May 7, 2011 10:15
Show Gist options
  • Save metamn/960384 to your computer and use it in GitHub Desktop.
Save metamn/960384 to your computer and use it in GitHub Desktop.
Create TOC on the fly
// Creating TOC
var toc = jQuery(".page #article #body .body > :header:not(h3,h4,h5,h6)");
if ( toc.size() > 0) {
jQuery(".page #article #aside #toc").removeClass('hidden');
var res = "<ul>";
toc.each(function(index) {
var ref = " id" + index;
var id = jQuery(this).attr("id");
jQuery(this).attr("id", id + ref);
res = res + "<li><a href='#" + ref + "'>" + this.innerHTML + '</a></li>';
});
res += "</ul>";
jQuery(".page #article #aside #toc").append(res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment