SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have a page that is really long, with marked Headers 1,2,3, etc. Would it be possible to create a webpart that will auto-generate the table of contents, based on the marked headers and put it in a column to the right?

I know that the webpart has a table of contents, but that only takes the whole site instead of a specific page. Any help greatly appreciated! :)

share|improve this question

This could be done with jQuery in an hour or two with properly defined content. You would need to identify a unique place in the document to generate the ToC as well as be able to identify the headers to be included. jQuery could even add Anchors in the content to allow for hyperlinks directly to the sections.

The actual syntax would vary depending on your structure and needs but basically you would use jQuery/javascript to grab the ToC Container, then use jQuery to search the rest of the page for the Header Text to be included and then dynamically build that list and write it into ToC Container as HTML. It would probably look something like this:

jQuery(".ClassOfHeaderText").each(function() {
   /// build new ToC Html with title / links
   newToCHtml += "<li>" + jQuery(this).text() + "</li>"

share|improve this answer
Could you even put that into reusable content field? Might be more straightforward for content editors if it would work from there. – Jussi Palo Feb 27 '13 at 20:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.