HTML and CSS Reference
In-Depth Information
Figure 14-4
creating the maketOc() function
runs the makeTO C() function
when the page is loaded
function to create the table
of contents
3. Save your changes to the file.
The first task of the makeTOC() function will be to identify the element in the cur-
rent document on which the table of contents is based, and the element where the TOC
should be inserted. The function also will use the innerHTML property introduced in the
last tutorial to write a heading for the table of contents box.
You'll add the initial code to the makeTOC() function now.
To modify the makeTOC() function:
1. Within the makeTOC() function, insert the following code, as shown in Figure 14-5:
/* Source document on which the TOC is based */
var source = document.getElementById(“doc”);
/* Location of the table of contents box */
var TOC = document.getElementById(“toc”);
/* Write a heading in the TOC box */
TOC.innerHTML = “<h1>Table of Contents</h1>”;
Figure 14-5
initial code of the maketOc() function
2. Save your changes to the file, and then reload usconst.htm in your Web browser.
Figure 14-6 shows the current appearance of the Web page.
Search WWH ::

Custom Search