You can find the demo of Automatically Generate Table of Contents with jQuery here..
I was earlier given a task to create a documentation for a web application that we have been working on. Since I’m lazy enough to create the table of contents which links to a particular part of the page, I look for a simpler solution – the Automatically Generate Table of Contents with jQuery.
I eventually landed to this page http://fuelyourcoding.com/table-of-contents-jquery-plugin/ by Doug Neiner.
I tested the jQuery Plugin he developed and made some css customization and eventually ended up using it in our project. Below is the code for the index.php file. You can find the remaining files by downloading the whole demo here: Automatically Generate Table of Contents with jQuery - 89 hits or you can visit the Downloads Section.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Automatically Generate Table of Contents with jQuery</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery.min.js" /></script>
<script type="text/javascript" src="js/jquery.tableofcontents.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("#toc").tableOfContents(
$("#maincontent"), // Scoped to div#wrapper
{
startLevel: 1, // H2 and up
depth: 5, // H2 through H5,
topLinks: true,
// Add "Top" Links to Each Header
}
);
});
</script>
</head>
<body>
<div id="main_container" class="clear">
<div id="header">
<img src="images/banner.png" alt="Automatically Generate Table of Contents with jQuery" title="Autmatically Generate Table of Contents with jQuery" border="0" />
</div>
<div id="left_container">
<div id="maincontent">
<h1>Main Category 1</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<h2>Level 2</h2>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
<h3>Level 3</h3>
<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
<h4>Level 4</h4>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
<h5>Level 5</h5>
<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
<h1>Main Category 2</h1>
<h2>Level 2</h2>
</div>
</div>
<div id="sidebar">
<div class="side_cont">
<h2>Table of Contents</h2>
<div id="toc-container"><ul id="toc"></ul></div>
</div>
</div>
<div class="side_bottom">
</div>
<div class="clear_sep"></div>
<div id="footer"><p><strong>Automatically Generate Table of Contents with jQuery</strong><br />Visit <a href='http://www.codingwhiz.com' style="color:#FFFFFF">CodingWhiz</a> for more information.</p>
</div>
</div>
</body
></html>
Download: Automatically Generate Table of Contents with jQuery - 89 hits
Demo: Automatically Generate Table of Contents with jQuery here.