AutoToc

Table of contents generator

About

AutoToc generates a table of contents list based on headings within an HTML document.

    Example

    Add a list element to your page:

    <ol id="toc">
    </ol>      
    

    Add AutoToc.js file to the page and run the AutoToc function, providing the list element id as an parameter:

    <script src="AutoToc.js"></script>
    <script>
      AutoToc("toc");
    </script>
    Download AutoToc.js View on Github

    Options

    Scope

    By default, AutoToc will provide a table of contents based on all headings available within the body html element. You can limit the table of contents scope by providing the id of a container element as a secondary, optional parameter.

    <script src="AutoToc.js"></script>
    <script>
      AutoToc("toc", "contents");
    </script>
    

    Default options

    There are additional options available via the AutoToc.defaultOptions object.

    AutoToc.defaultOptions = {
      startLevel: 1,
      depth: 3,
      showTopLinks: false,
      topLinkToParentToc: false,
      topLinkClass: "autoTocTopLink",
      topBodyId: "top",
    };
    

    Usage:

    <script src="AutoToc.js"></script>
    <script>
      AutoToc("toc", "contents", { startLevel: 2, showTopLinks: true });
    </script>
    

    Example table of contents


    Heading 1 - level 1

    Barbary Coast tackle Gold Road Buccaneer long boat quarter ballast crack Jennys tea cup me loot. Pirate Round case shot come about Brethren of the Coast Privateer spirits jack rum aye rope's end. Aye cog barque bilge rat hearties port provost hogshead splice the main brace driver.

    Heading 2 - level 1.1

    Hogshead measured fer yer chains booty blow the man down jib gaff cackle fruit bilge water pink boatswain. Yo-ho-ho sheet gabion bowsprit bilge water hail-shot mutiny splice the main brace gaff schooner. Avast Barbary Coast poop deck weigh anchor case shot gunwalls hearties chandler take a caulk mutiny.

    Heading 3 - level 1.1.1

    Pink rutters cable jolly boat hogshead Jack Ketch keelhaul Admiral of the Black ho shrouds. Grog gibbet starboard clap of thunder Sea Legs jack mizzen draft gabion scourge of the seven seas. Sloop main sheet Davy Jones' Locker sheet rum lass black jack keelhaul measured fer yer chains gabion.

    Heading 3 - level 1.1.2

    Barbary Coast tackle Gold Road Buccaneer long boat quarter ballast crack Jennys tea cup me loot. Pirate Round case shot come about Brethren of the Coast Privateer spirits jack rum aye rope's end. Aye cog barque bilge rat hearties port provost hogshead splice the main brace driver.

    Hogshead measured fer yer chains booty blow the man down jib gaff cackle fruit bilge water pink boatswain. Yo-ho-ho sheet gabion bowsprit bilge water hail-shot mutiny splice the main brace gaff schooner. Avast Barbary Coast poop deck weigh anchor case shot gunwalls hearties chandler take a caulk mutiny.

    Pink rutters cable jolly boat hogshead Jack Ketch keelhaul Admiral of the Black ho shrouds. Grog gibbet starboard clap of thunder Sea Legs jack mizzen draft gabion scourge of the seven seas. Sloop main sheet Davy Jones' Locker sheet rum lass black jack keelhaul measured fer yer chains gabion.

    Heading 2 - level 1.2

    Pink rutters cable jolly boat hogshead Jack Ketch keelhaul Admiral of the Black ho shrouds. Grog gibbet starboard clap of thunder Sea Legs jack mizzen draft gabion scourge of the seven seas. Sloop main sheet Davy Jones' Locker sheet rum lass black jack keelhaul measured fer yer chains gabion.

    Heading 3 - level 1.2.1

    Hogshead measured fer yer chains booty blow the man down jib gaff cackle fruit bilge water pink boatswain. Yo-ho-ho sheet gabion bowsprit bilge water hail-shot mutiny splice the main brace gaff schooner. Avast Barbary Coast poop deck weigh anchor case shot gunwalls hearties chandler take a caulk mutiny.

    Heading 3 - level 1.2.2

    Barbary Coast tackle Gold Road Buccaneer long boat quarter ballast crack Jennys tea cup me loot. Pirate Round case shot come about Brethren of the Coast Privateer spirits jack rum aye rope's end. Aye cog barque bilge rat hearties port provost hogshead splice the main brace driver.

    Heading 4 - level 1.2.2.1

    Chase guns poop deck reef stern mizzen trysail ahoy holystone Pirate Round grapple. Jack Tar hail-shot matey gangplank Sink me weigh anchor black jack run a shot across the bow dead men tell no tales Blimey. Spirits lad mizzen log hardtack lass sutler fore mutiny black jack.

    Heading 4 - level 1.2.2.2

    Sink me weigh anchor long clothes handsomely swing the lead boatswain reef Chain Shot dance the hempen jig fire ship. Me handsomely come about topgallant bucko chase take a caulk carouser black jack haul wind. Cog Sail ho prow aft strike colors American Main Chain Shot rutters lookout interloper.

    Heading 5 - level 1.2.2.2.1

    Pink rutters cable jolly boat hogshead Jack Ketch keelhaul Admiral of the Black ho shrouds. Grog gibbet starboard clap of thunder Sea Legs jack mizzen draft gabion scourge of the seven seas. Sloop main sheet Davy Jones' Locker sheet rum lass black jack keelhaul measured fer yer chains gabion.

    Heading 5 - level 1.2.2.2.2

    Barbary Coast tackle Gold Road Buccaneer long boat quarter ballast crack Jennys tea cup me loot. Pirate Round case shot come about Brethren of the Coast Privateer spirits jack rum aye rope's end. Aye cog barque bilge rat hearties port provost hogshead splice the main brace driver.

    Heading 5 - level 1.2.2.2.3

    Pink rutters cable jolly boat hogshead Jack Ketch keelhaul Admiral of the Black ho shrouds. Grog gibbet starboard clap of thunder Sea Legs jack mizzen draft gabion scourge of the seven seas. Sloop main sheet Davy Jones' Locker sheet rum lass black jack keelhaul measured fer yer chains gabion.

    Heading 6 - level 1.2.2.2.3.1

    Pink rutters cable jolly boat hogshead Jack Ketch keelhaul Admiral of the Black ho shrouds. Grog gibbet starboard clap of thunder Sea Legs jack mizzen draft gabion scourge of the seven seas. Sloop main sheet Davy Jones' Locker sheet rum lass black jack keelhaul measured fer yer chains gabion.

    Heading 2 - level 1.3

    Hogshead measured fer yer chains booty blow the man down jib gaff cackle fruit bilge water pink boatswain. Yo-ho-ho sheet gabion bowsprit bilge water hail-shot mutiny splice the main brace gaff schooner. Avast Barbary Coast poop deck weigh anchor case shot gunwalls hearties chandler take a caulk mutiny.

    Heading 3 - level 1.3.1

    Chase guns poop deck reef stern mizzen trysail ahoy holystone Pirate Round grapple. Jack Tar hail-shot matey gangplank Sink me weigh anchor black jack run a shot across the bow dead men tell no tales Blimey. Spirits lad mizzen log hardtack lass sutler fore mutiny black jack.

    Heading 3 - level 1.3.2

    Sink me weigh anchor long clothes handsomely swing the lead boatswain reef Chain Shot dance the hempen jig fire ship. Me handsomely come about topgallant bucko chase take a caulk carouser black jack haul wind. Cog Sail ho prow aft strike colors American Main Chain Shot rutters lookout interloper.