Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Project day_31
<!DOCTYPE html>
<title>Table of Contents - Missing IDs</title>
<style type="text/css">
body {
margin: 1em auto;
max-width: 40em;
width: 88%;
h2 {
text-align: center;
background-color: #ffffff;
background-image: url("data:image/svg+xml,%3Csvg xmlns='' width='80' height='80' viewBox='0 0 90 90'%3E%3Ccircle fill='%23ffe712' cx='45' cy='45' r='24'/%3E%3Cg fill='%23ff1cec' fill-opacity='1'%3E%3Ccircle cx='0' cy='90' r='14'/%3E%3Ccircle cx='90' cy='90' r='14'/%3E%3Ccircle cx='90' cy='0' r='14'/%3E%3Ccircle cx='0' cy='0' r='14'/%3E%3C/g%3E%3C/svg%3E");
background-attachment: fixed;
background-size: cover; }
<h1>Table of Contents - Missing IDs</h1>
<div id="table-of-contents"></div>
<h2>Cat O'Nine Tails</h2>
<p>Cat o'nine tails Pieces of Eight swab carouser tackle. Pink hornswaggle gabion Sea Legs Davy Jones' Locker.</p>
<p>Hang the jib Nelsons folly trysail ahoy prow. Transom strike colors scallywag aft league.</p>
<h3 id="the-brig">The Brig</h3>
<p>Dead men tell no tales topmast Sail ho Davy Jones' Locker chantey. Wherry fluke pillage rope's end brig.</p>
<p>Tack topgallant draft line flogging. Maroon overhaul grog blossom Privateer main sheet.</p>
<p>Provost me cackle fruit Corsair Cat o'nine tails. Hempen halter Davy Jones' Locker clipper bring a spring upon her cable run a shot across the bow.</p>
<p>Booty squiffy wench overhaul ahoy. Parrel Pirate Round long clothes long boat come about.</p>
<p>Squiffy jack crow's nest bilged on her anchor barkadeer. Snow bucko mizzen six pounders tack.</p>
<h3 id="man-of-war">Man-of-War</h3>
<p>Lee lad nipperkin avast pressgang. Man-of-war prow ho Sail ho landlubber or just lubber.</p>
<p>Ho no prey, no pay fire ship salmagundi capstan. Hail-shot doubloon wherry loaded to the gunwalls cutlass.</p>
<h2 id="corsair">Corsair</h2>
<p>Corsair chantey hardtack ahoy snow. Maroon cog galleon topmast tender.</p>
<h3 id="shiver-me-timbers">Shiver Me Timbers</h3>
<p>Galleon nipper Shiver me timbers lugger Nelsons folly. Wench ballast scurvy man-of-war hearties.</p>
<p>Poop deck clap of thunder Corsair grog hornswaggle. Dead men tell no tales brigantine long clothes black spot sutler.</p>
<h4 id="scurvy-dog">Scurvy Dog</h4>
<p>Jury mast Letter of Marque boatswain scurvy sheet. Jolly boat plunder jack starboard Pirate Round.</p>
<p>Holystone bring a spring upon her cable grog blossom deadlights league. Lanyard gabion reef sails booty gaff.</p>
<h4>Sea Legs</h4>
<p>Sea Legs to go on account skysail Yellow Jack heave down. Spanker heave down yawl starboard barque.</p>
<p>To go on account hulk swing the lead heave to tack. Fore fire in the hole prow run a rig Jack Ketch.</p>
<h2 id="quarterdeck">On the Quarterdeck</h2>
<p>Tack chase red ensign league pinnace. Holystone quarterdeck me boatswain rope's end.</p>
<p>Sink me lanyard Pieces of Eight starboard black spot. Blimey heave down crimp mutiny matey.</p>
<h3 id="jolly-roger">Jolly Roger</h3>
<p>Belay piracy come about jolly boat transom. Heave to gally snow Arr wherry.</p>
<p>Sutler Davy Jones' Locker ahoy walk the plank lugger. Jolly Roger matey hornswaggle Privateer marooned.</p>
<h2>Davy Jones' Locker</h2>
<p>Davy Jones' Locker jib trysail bowsprit heave down. Transom square-rigged clipper Jack Ketch chandler.</p>
<p>Square-rigged yawl execution dock sloop American Main. Six pounders red ensign lugger heave to dead men tell no tales.</p>
<h3 id="sloop">Sloop</h3>
<p>Spanker rutters Arr sloop pinnace. List crimp swab Blimey grog.</p>
<p>Shiver me timbers hulk black jack Pirate Round clap of thunder. Scuppers six pounders carouser spirits jib.</p>
<em>Text provided by <a href="">Pirate Ipsum</a>.</em>
// Get the table of contents container
var tableOfContents = document.querySelector('#table-of-contents');
// Get all of the h2 headings in the document
var headings = document.querySelectorAll('h2');
// Make sure there's at least one heading
// Only generate markup if there are heading elements
if (headings.length > 0) {
// Set the HTML for the table of contents container
// Add a heading and an ordered list
// Convert the headings NodeList to an array, and use the method
// to create an array of markup strings that we'll combine with the array.join() method
tableOfContents.innerHTML =
'<h2>Shortcuts to Contents</h2>' +
'<ol aria-live="polite ">' + (heading) {
if ( === 0) {
heading.setAttribute('id',heading.textContent.replace(new RegExp(' ', 'g'), '_').replace(new RegExp("'", 'g'), '_'));
return '<li><a href="#' + + '">' + heading.textContent + '</a></li>';
}).join('') +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment