This version is old school.
Please find jQuery plugins on npm.
Table of Contents jQuery Plugin
by Nikhil Dabas
jquery.toc is a minimal, tiny jQuery plugin that will generate a table of contents, drawing from headings on the page.