In this exercise you are going to traverse an unordered list that has several nested lists inside it. Your task is to count the number of descendant <li> elements of every
<li> element in the list and add the count to each element. You must skip adding counts numbers to the
<li> elements that have no descendants.
The before and after of the lists is shown in the image below. Notice how on the right side there are numbers in parentheses after many list items. Those are the counts of the descendant
<li> elements inside that particular list item. Notice how Animals list item has 17 descendant list item, which include all the list items, as in this example all other list items are descendants of Animals list item in the DOM.
The before and after of the lists
Start by making sure you are in your local clone of the Git repository, and in its exercises/03_javascript/ex3 directory. Then:
index.html file inside this directory. Open this file in your browser. Remember to open the developer console to see any errors in your code. DO NOT EDIT THIS
FILE!
Your code will be tested with different list and data. DO NOT assume anything about the depth of nesting or the number of list items!
element.getElementsByTagName(), element.getElementsByClassName(), and
element.querySelectorAll() return all matching elements even if they are not the immediate children of the element. This is useful in calculating element's descendants.
querySelectorAll(), can be looped through with forEach()
methodText node(s) which can be manipulated independently of other nodes such as elements. The text inside these nodes can be accessed with
node.nodeValue and node.data.
Remember to commit dom-tree.js and push the changes to your Git repository before you submit your work in Plussa.
Submitting Your Project to Plussa
PLEASE NOTE: You should copy-paste the git@.... url, not the https://... url