This commit is contained in:
Ilya Kantor 2017-03-05 19:49:29 +03:00
parent 7b3f4550fd
commit d85be5f17b
12 changed files with 47 additions and 93 deletions

View file

@ -2,7 +2,7 @@ importance: 1
---
# Why "ааа" remains?
# Why "aaa" remains?
Run the example. Why `table.remove()` does not delete the text `"aaa"`?

View file

@ -27,7 +27,7 @@
container.innerHTML = createTreeText(obj);
}
function createTreeText(obj) { // отдельная рекурсивная функция
function createTreeText(obj) { // standalone recursive function
let li = '';
for (let key in obj) {
li += '<li>' + key + createTreeText(obj[key]) + '</li>';
@ -38,7 +38,6 @@
return ul || '';
}
let container = document.getElementById('container');
createTree(container, data);
</script>
</body>

View file

@ -43,12 +43,12 @@
let lis = document.getElementsByTagName('li');
for (let li of lis) {
// получить количество детей
let childCount = li.getElementsByTagName('li').length;
if (!childCount) continue;
// get the count of all <li> below this <li>
let descendantsCount = li.getElementsByTagName('li').length;
if (!descendantsCount) continue;
// добавить кол-во детей к текстовому узлу
li.firstChild.data += ' [' + childCount + ']';
// add directly to the text node (append to the text)
li.firstChild.data += ' [' + descendantsCount + ']';
}
</script>