Skip to content

Instantly share code, notes, and snippets.

@MichaelCPell
Created November 6, 2015 10:49
Show Gist options
  • Select an option

  • Save MichaelCPell/d89efa0397abc3d21793 to your computer and use it in GitHub Desktop.

Select an option

Save MichaelCPell/d89efa0397abc3d21793 to your computer and use it in GitHub Desktop.
Making a Table of Contents from H2's
// Step 1: Collect all of the H2's into a variable
$headings = $("h2")
// Step 2: Iterate through them and add some text
$.each($headings, function(index, value){
$("#toc-container").append("<li>" + $(value).html() +"</li>")
})
@jgrant29

jgrant29 commented Nov 6, 2015

Copy link
Copy Markdown

Dude, you're the man! I got this to work on the chapter show page. Now I need to figure out how to make the "h2" list into anchors within the content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment