With the help of a loop, I want to add an element into my list items.
Thanks a bunch for any advice!
It's a little hard to tell the context of your problem, but I think using a for...of loop would better meet your needs, as it works with each item of the list individually.
Try this:
let item = document.getElementsByTagName('li');
for (let i of item){
i.innerHTML = `${i.innerText} <span class="credits">100 credits</span>`;
}
If you need something that specifically uses an index loop, try this:
let item = document.getElementsByTagName('li');
for (let i = 0; i < item.length; i++){
item[i].innerHTML = `${item[i].innerText} <span class="credits">100 credits</span>`;
}
itemsis your NodeList of<li>elements, thenitems[i]would refer to the specific<li>at that index.