This question has already been answered:
- How to use (run) class in loop 1 answer
In the cycle, for each pass, 1 new list item should be created - li, so that the total would be 10 list items. However, it gives only 1 point. How to fix?
let out = document.getElementById('out'); let ul = document.createElement('ul'); let li = document.createElement('li'); out.appendChild(ul); for (let i = 0; i < 11; i++) { ul.appendChild(li); ul.children[i] = li; } console.log(ul.children.length); ul { height: 50px; width: 250px; border: 1px solid #000; margin: 10px auto; padding-left: 0; list-style-type: none; } li { background-color: gray; border: 1px solid #000; width: 12px; height: 25px; } <p id="out"></p>
ul.children[i] = li;need not. - Grundy