en.javascript.info/2-ui/1-document/05-basic-dom-node-properties/2-tree-info/solution.md
2019-05-31 19:11:37 +03:00

21 lines
474 B
Markdown

Let's make a loop over `<li>`:
```js
for (let li of document.querySelectorAll('li')) {
...
}
```
In the loop we need to get the text inside every `li`.
We can read the text from the first child node of `li`, that is the text node:
```js
for (let li of document.querySelectorAll('li')) {
let title = li.firstChild.data;
// title is the text in <li> before any other nodes
}
```
Then we can get the number of descendants as `li.getElementsByTagName('li').length`.