HTML and CSS Reference
In-Depth Information
Creating Nodes
• To create an element node, use the method
document.createElement( text );
where text is the name of the element.
• To create an attribute node, use the method
document.createAttribute( text );
where text is the name of the attribute.
• To create a text node, use the method
document.createTextNode( text );
where text is the text string of the text node.
• To create a comment node, use the method
document.createComment( text );
where text is the text of the comment.
• To copy a preexisting node, use the method
node .cloneNode( deep )
where node is the preexisting node, and deep is a Boolean value indicating whether to
copy all descendants of the node ( true ) or only the node itself ( false ).
You'll use the createElement() method now to create an ordered list element, add-
ing the command to the makeTOC() function.
To create an ordered list element:
1. Return to the toc.js file in your text editor.
2. Within the makeTOC() function, add the following command as shown in Figure 14-11:
/* Create an ordered list element */
var TOCList = document.createElement(“ol”);
Figure 14-11
creating an element node
3. Save your changes to the file.
Search WWH ::




Custom Search