en.javascript.info/2-ui/1-document/04-searching-elements-dom/2-tree-info/solution.md
Ilya Kantor d110eb3ea8 minor
2017-03-30 17:47:55 +03:00

452 B

Let's make a loop over <li>:

for (let li of document.querySelector('li')) {
  ...
}

In the loop we need to get the text inside every li. We can read it directly from the first child node, that is the text node:

for (let li of document.querySelector('li')) {
  let title = li.firstChild.data;

  // title is the text in <li> before any other nodes
}

Then we can get the number of descendants li.getElementsByTagName('li').