HTML and CSS Reference
about this shortly. In the Constitution document, you need to use only elements h1
through h3 ; however, including the full range of headings allows you to generalize the
makeTOC() function for other documents in Norene's library.
You'll add the headings array to the makeTOC() function now, and then you'll create a
command to call the createList() function.
To call the createList() function:
1. Scroll up to the makeTOC() function in the toc.js file, and then insert the following
command directly after the command that declares the TOC variable:
To create a table of contents
based on sections marked
by elements other than
headings, change the ele-
ment names listed in the
/* Entries in the source document on which the
table of contents is based */
var headings = [“H1”, “H2”, “H3”, “H4”, “H5”, “H6”];
2. At the bottom of the function, add the following command to call the createList()
/* Create the list of table of contents entries */
createList(source, TOCList, headings);
Figure 14-16 highlights the revised code in the function.
revised maketOc() function
array of elements from
the source document
calls the function to
generate items in the
3. Save your changes to the file.