Initialize Tocbot
masterTo build a table of contents, call tocbot.init() with a configuration object.
Important Requirements:
- The document headings must have
idattributes so the browser can jump to them via hashes. - Ensure the
bodyis scrollable. - If your headings are inside relative or absolute positioned containers within the content area, set
hasInnerContainers: true.
tocbot.init({
// Where to render the table of contents.
tocSelector: '.js-toc',
// Where to grab the headings to build the table of contents.
contentSelector: '.js-toc-content',
// Which headings to grab inside of the contentSelector element.
headingSelector: 'h1, h2, h3',
// For headings inside relative or absolute positioned containers within content.
hasInnerContainers: true,
});