Question: JAVASCRIPT Hello, I need some help getting my code to populate a web page. Any help would be great. Please edit code as needed. CODE
JAVASCRIPT
Hello, I need some help getting my code to populate a web page. Any help would be great.
Please edit code as needed.
CODE
"use strict";
/* JavaScript 7th Edition
Chapter 5
Project 05-03
Project to create a table of headings from an article
Author:
Date:
Filename: Individual Project
*/
let sourceDoc = document.getElementById("source_doc");
let toc = document.getElementById("toc");
let headingCount =1;
const heading = "H2";
for (let n = sourceDoc.firstElementChild; n !== null; n = n.nextElementSibling)
{
if (n.nodeName === heading)
{
let anchor = document.createElement("a");
anchor.name = "doclink" + headingCount;
n.insertBefore(anchor, n.firstElementChild);
let listItem = document.createElement("li");
let link = document.createElement("a");
listItem.appendChild(link);
link.textContent = n.textContent;
link.href = "#" + "doclink" + headingCount;
toc.appendChild(listItem);
headingCount++;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
