Table of Contents Generator is a small script I wrote to create a table of contents based off of the header tags(h1-h6) throughout a page. In fact I wrote it for this very site.

Browser Support

This script has been found to work in IE5+,Safari,Firefox 1+, and Opera 7+. If you are viewing this page in another browser, and it works, feel free to tell me about it in the comments.

Demo

The demo above is generated dynamically based of off this page. This is script is also used on every page of this site to generate that table of contents found when you click on the "Table Of Contents" link found near the top of the page.

Usage

Here I will go over how to use the script

Download

First of all you need to download the single javascript file here. Save this as toc.js in the same directory as the file you would like to use it on.

Adding the code

Then, in the head of that file add this.

<script type="text/javascript" src="toc.js">//ToC Generator - By Brady Mulhollem - WebTech101.com</script>

And in the body add this(where you want the Table to appear)

<div id="toc"></div>

The part you need to edit is this(second line of toc.js)

function(){new tocGen('top','toc')}

Change top to the id of the element you want the table to based off of(all the header tags must be direct descendants), and toc to the id of the div you added to the body.If you followed these directions exactly you don't need to change toc.

Questions?

Feel free to ask in the comments


Warning: WARNING: Comments is not properly cleaning input params. in /home/freegam4/public_html/webtech/lib/classes/class.module.inc.php on line 1500

Comments

Posted on November 6, 2007, 12:53 pm by Brian

Does not work in IE6.
The menu on the left isd really buggy when you resize the browser window.

Posted on October 14, 2006, 8:05 am by Brady Mulhollem

Thanks for the info Sam. I have updated the page.

Posted on October 12, 2006, 9:39 am by sam@DHP

works in safari on mac

Add A Comment

10 + 3 =
Your Name(*):
Email:
Comment(*):