-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdescendantsCount.html
More file actions
56 lines (51 loc) · 1.28 KB
/
descendantsCount.html
File metadata and controls
56 lines (51 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE HTML>
<html>
<body>
<ul>
<li>Животные
<ul>
<li>Млекопитающие
<ul>
<li>Коровы</li>
<li>Ослы</li>
<li>Собаки</li>
<li>Тигры</li>
</ul>
</li>
<li>Другие
<ul>
<li>Змеи</li>
<li>Птицы</li>
<li>Ящерицы</li>
</ul>
</li>
</ul>
</li>
<li>Рыбы
<ul>
<li>Аквариумные
<ul>
<li>Гуппи</li>
<li>Скалярии</li>
</ul>
</li>
<li>Морские
<ul>
<li>Морская форель</li>
</ul>
</li>
</ul>
</li>
</ul>
<script>
let lis = document.getElementsByTagName('li');
for (let li of lis) {
// получить количество всех <li> ниже этого <li>
let descendantsCount = li.getElementsByTagName('li').length;
if (!descendantsCount) continue;
// добавить непосредственно к текстовому узлу (добавить к тексту)
li.firstChild.data += ' [' + descendantsCount + ']';
}
</script>
</body>
</html>