Skip to main content
#toc{display: table;border: 1px solid #aaa;background-color: #f9f9f9;font-size: 95%;padding: 7px;}#toc #tocHeader{font-weight: bold;text-align: center;}#toc a:before{/* content:"• "; */}#toc a{ line-height: 15px; margin: 10px;}#toc.toc_Level1{ margin-left: 5px;}#toc.toc_Level2{ margin-left: 15px;}#toc.toc_Level3{ margin-left: 25px;}#toc.toc_Level4{ margin-left: 35px;}function GenerateTOC(){$("#toc").append('Contents

');$(".ms-webpart-titleText h1,.ms-webpart-titleText h2,.ms-webpart-titleText h3,.ms-webpart-titleText h4,.ms-webpart-titleText > a").each(function(i){var currentNode = $(this);currentNode.attr("id", "title" + i);var linkClass =(currentNode.hasClass('h1'))? "toc_Level1":(currentNode.hasClass('h2'))? "toc_Level2":(currentNode.hasClass('h3'))? "toc_Level3":(currentNode.hasClass('h4'))? "toc_Level4": "";$("#toc").append("" + currentNode.html() + "
");currentNode.append(" [top]");});}$(document).ready(function(){_spBodyOnLoadFunctionNames.push('GenerateTOC');});_spBodyOnLoadFunctionNames.push('GenerateTOC');
<style>
   #toc {
      display: table;
      border: 1px solid #aaa;
      background-color: #f9f9f9;
      font-size: 95%;
      padding: 7px;
   }
   #toc #tocHeader  {
      font-weight: bold;
      text-align: center;
   }
   #toc a:before { /* content:"• "; */ }
   #toc a { line-height: 15px; margin: 10px; }
   #toc .toc_Level1 { margin-left: 5px; }
   #toc .toc_Level2 { margin-left: 15px; }
   #toc .toc_Level3 { margin-left: 25px; }
   #toc .toc_Level4 { margin-left: 35px; }

</style>

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

<script src="https://sites.ey.com/sites/EYSE/Shared%20Documents/jquery.SPServices.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
   function GenerateTOC() {
      $("#toc").append('<p id="tocHeader">Contents</p>');
      $(".ms-webpart-titleText h1,.ms-webpart-titleText h2,.ms-webpart-titleText h3,.ms-webpart-titleText h4,.ms-webpart-titleText > a").each(function(i) {
         var currentNode = $(this);
         currentNode.attr("id", "title" + i);
         var linkClass = (currentNode.hasClass('h1') )? "toc_Level1": (currentNode.hasClass('h2') )? "toc_Level2": (currentNode.hasClass('h3') )? "toc_Level3" : (currentNode.hasClass('h4'))? "toc_Level4": "";

         $("#toc").append("<a id='link'" + i + "' class='" + linkClass + "' href='#title" + i + "' title='" + currentNode.attr("tagName") + "'>" + currentNode.html() + "</a><br>");
         currentNode.append(" <a href='#tocHeader'>[top]</a>");
      });
   }
   $(document).ready(function() 
       _spBodyOnLoadFunctionNames.
       push('GenerateTOC');
   });

   _spBodyOnLoadFunctionNames.
   push('GenerateTOC');
 </script>
#toc{display: table;border: 1px solid #aaa;background-color: #f9f9f9;font-size: 95%;padding: 7px;}#toc #tocHeader{font-weight: bold;text-align: center;}#toc a:before{/* content:"• "; */}#toc a{ line-height: 15px; margin: 10px;}#toc.toc_Level1{ margin-left: 5px;}#toc.toc_Level2{ margin-left: 15px;}#toc.toc_Level3{ margin-left: 25px;}#toc.toc_Level4{ margin-left: 35px;}function GenerateTOC(){$("#toc").append('Contents

');$(".ms-webpart-titleText h1,.ms-webpart-titleText h2,.ms-webpart-titleText h3,.ms-webpart-titleText h4,.ms-webpart-titleText > a").each(function(i){var currentNode = $(this);currentNode.attr("id", "title" + i);var linkClass =(currentNode.hasClass('h1'))? "toc_Level1":(currentNode.hasClass('h2'))? "toc_Level2":(currentNode.hasClass('h3'))? "toc_Level3":(currentNode.hasClass('h4'))? "toc_Level4": "";$("#toc").append("" + currentNode.html() + "
");currentNode.append(" [top]");});}$(document).ready(function(){_spBodyOnLoadFunctionNames.push('GenerateTOC');});_spBodyOnLoadFunctionNames.push('GenerateTOC');
<style>
   #toc {
      display: table;
      border: 1px solid #aaa;
      background-color: #f9f9f9;
      font-size: 95%;
      padding: 7px;
   }
   #toc #tocHeader  {
      font-weight: bold;
      text-align: center;
   }
   #toc a:before { /* content:"• "; */ }
   #toc a { line-height: 15px; margin: 10px; }
   #toc .toc_Level1 { margin-left: 5px; }
   #toc .toc_Level2 { margin-left: 15px; }
   #toc .toc_Level3 { margin-left: 25px; }
   #toc .toc_Level4 { margin-left: 35px; }

</style>

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

<script src="https://sites.ey.com/sites/EYSE/Shared%20Documents/jquery.SPServices.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
   function GenerateTOC() {
      $("#toc").append('<p id="tocHeader">Contents</p>');
      $(".ms-webpart-titleText h1,.ms-webpart-titleText h2,.ms-webpart-titleText h3,.ms-webpart-titleText h4,.ms-webpart-titleText > a").each(function(i) {
         var currentNode = $(this);
         currentNode.attr("id", "title" + i);
         var linkClass = (currentNode.hasClass('h1') )? "toc_Level1": (currentNode.hasClass('h2') )? "toc_Level2": (currentNode.hasClass('h3') )? "toc_Level3" : (currentNode.hasClass('h4'))? "toc_Level4": "";

         $("#toc").append("<a id='link'" + i + "' class='" + linkClass + "' href='#title" + i + "' title='" + currentNode.attr("tagName") + "'>" + currentNode.html() + "</a><br>");
         currentNode.append(" <a href='#tocHeader'>[top]</a>");
      });
   }
   $(document).ready(function() 
       _spBodyOnLoadFunctionNames.
       push('GenerateTOC');
   });

   _spBodyOnLoadFunctionNames.
   push('GenerateTOC');
 </script>
Source Link

for webpart pages:

#toc { display: table; border: 1px solid #aaa; background-color: #f9f9f9; font-size: 95%; padding: 7px; } #toc #tocHeader { font-weight: bold; text-align: center; } #toc a:before { /* content:"• "; */ } #toc a { line-height: 15px; margin: 10px; } #toc .toc_Level1 { margin-left: 5px; } #toc .toc_Level2 { margin-left: 15px; } #toc .toc_Level3 { margin-left: 25px; } #toc .toc_Level4 { margin-left: 35px; } function GenerateTOC() { $("#toc").append('Contents

'); $(".ms-webpart-titleText h1,.ms-webpart-titleText h2,.ms-webpart-titleText h3,.ms-webpart-titleText h4,.ms-webpart-titleText > a").each(function(i) { var currentNode = $(this); currentNode.attr("id", "title" + i); var linkClass = (currentNode.hasClass('h1') ) ? "toc_Level1" : (currentNode.hasClass('h2') ) ? "toc_Level2" : (currentNode.hasClass('h3') ) ? "toc_Level3" : (currentNode.hasClass('h4')) ? "toc_Level4" : ""; $("#toc").append("" + currentNode.html() + "
"); currentNode.append(" [top]"); }); } $(document).ready(function(){ _spBodyOnLoadFunctionNames.push('GenerateTOC'); }); _spBodyOnLoadFunctionNames.push('GenerateTOC');