HTML and CSS Reference
In-Depth Information
4. Finally, after the if structure, insert the following statements to update the value
of the prevLevel variable to reflect the level of the current list item:
/* Update the previous node level value to the current level */
prevLevel = nodeLevel;
Figure 14-24 shows the revised code in the function.
Figure 14-24
inserting the if structure for creating nested lists
replaces the
statement that
appends the list
item with the if
updates the value
of the prevLevel
5. Save your changes to the file.
Next, you will enter the code for each if condition. First, if nodeLevel equals prevLevel ,
then the current node is at the same level as the previous entry and you simply need to
append the new entry to the current list. Figure 14-25 shows how creating and appending
such a node to the node tree corresponds to directly inserting the code in an HTML fragment.
Figure 14-25
appending a list item
<li>item 1</li>
<li>item 2</li>
HTML fragment
"item 1"
"item 2"
corresponding node tree
Search WWH ::

Custom Search