Automatic-table-of-contents
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 - 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);
Developer | Rich Wertz |
Username | richwertz |
Uploaded | January 29, 2023 |
Rating | 3 |
Size | 2,799 Kb |
Views | 6,072 |
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!
Name | Size |
JQuery1 | 1,429 Kb |
Subtle Background Image Animation | 1,734 Kb |
Vertical-align-vertical-height | 2,232 Kb |
Shivering Text Effect for Navigation | 1,607 Kb |
SCSS basics | 1,824 Kb |
Animated Title Effect | 1,860 Kb |
Color Palette Changer | 2,137 Kb |
Adaptive Background Colors | 6,171 Kb |
Video-background | 2,002 Kb |
A Pen by Rich Wertz | 1,598 Kb |
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!
Name | Username | Size |
A Bouncy Menu Toggle | Billyysea | 4,563 Kb |
Acorrdian 2016 | Milanodituti | 3,720 Kb |
CSS only simple parallax scroll | Stanssongs | 3,708 Kb |
Tab Menus | Zephyr | 3,180 Kb |
Learning FlexBox | Alex_rodrigues | 2,821 Kb |
Simple Accordion | Wearebold | 3,683 Kb |
Pure CSS read more toggle | Idered | 2,344 Kb |
Get third wednesday | Wojtek1150 | 2,691 Kb |
Twitch JSON API | Jvhti | 2,808 Kb |
React Vote Component | Souporserious | 5,465 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!