Automatic-table-of-contents

Developer
Size
2,799 Kb
Views
6,072

How do I make an automatic-table-of-contents?

Using JS to hunt for a particular tag class based on ID, add contents of that tag to a content section. The last item in the list should not have a pipe divider.. What is a automatic-table-of-contents? How do you make a automatic-table-of-contents? This script and codes were developed by Rich Wertz on 29 January 2023, Sunday.

Automatic-table-of-contents Previews

Automatic-table-of-contents - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>automatic-table-of-contents</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<article> <h1>Automatic Table of Contents</h1> <p>Using JS to hunt for a particular tag class based on ID, add contents of that tag to a content section. The last item in the list should not have a pipe divider.</p> <div class="all-questions" id="pagecontents"> <h3 class="pintro" id="one">Why is the sky blue?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintroq" id="two">Where do baby pidgeons live?</h3> <p>*This section head isn't in the page contents, because the class name is different that what is being looked for in the JS script.<br>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="three">Amsterdam canal tours</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="four">Symbolism of a red church door</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="five">Why is Doug?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="six">The ultimate answer to everything</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="seven">How to drink water in space</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="eight">After all the hangers on</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 class="pintro" id="nine">Are done hanging on</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> </div>
</article> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Automatic-table-of-contents - Script Codes CSS Codes

body { background: #eee; padding: 20px;
}
article { max-width: 50em; background: white; padding: 2em; margin: 1em auto;
}
.table-of-contents { float: right; width: 40%; background: #eee; font-size: 0.8em; padding: 1em 2em; margin: 0 0 0.5em 0.5em;
}
.table-of-contents ul { padding: 0;
}
.table-of-contents li { margin: 0 0 0.25em 0;
}
.table-of-contents a { text-decoration: none;
}
.table-of-contents a:hover,
.table-of-contents a:active { text-decoration: underline;
}
h3:target { animation: highlight 1s ease;
}
@keyframes highlight { from { background: yellow; } to { background: white; }
}

Automatic-table-of-contents - Script Codes JS Codes

var ToC = "<p class='contents'>Contents</p>";
var el, title, link, $navlist, thisVal;
$navlist =
$("article h3.pintro"); $navlist.each(function(idx) { el = $(this); title = el.text(); link = "#" + el.attr("id"); newLine = "<a class='contents' href='" + link + "'>" + title + "</a>"; var array = new Array(idx); if (idx == $navlist.length-1) { sep = ""; } else { sep = " | "; }; ToC += newLine + sep;
}); console.log($navlist.length);
ToC += "";
$("#pagecontents").prepend(ToC);
Automatic-table-of-contents - Script Codes
Automatic-table-of-contents - Script Codes
Home Page Home
Developer Rich Wertz
Username richwertz
Uploaded January 29, 2023
Rating 3
Size 2,799 Kb
Views 6,072
Do you need developer help for Automatic-table-of-contents?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Rich Wertz (richwertz) Script Codes
Create amazing love letters with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!