-1

The array gets console logged fine, but only the last person of the array is inserted in the HTML <div>.

Why or what is the failure?

document.getElementById("team").addEventListener("click", show)
function show(){
    document.getElementById("fritz").style.display = "block";
    document.getElementById("bill").style.display = "block";
    document.getElementById("fran").style.display = "block";



    for (i = 0; i < people.length; i++) {

        var persoxn = people[i].printinfos()

        document.getElementById('insert_text').innerHTML = persoxn

        console.log(persoxn)
     }
}

(https://i.stack.imgur.com/HigAY.jpg) console

D. Pardal
  • 6,173
  • 1
  • 17
  • 37

1 Answers1

0

You are overriding (replacing) the <div> content in each iteration, therefore all of the elements except the last one get overwritten.

Maybe you meant to use .insertAdjacentHTML():

    for (let i = 0; i < people.length; i++) {
        var person = people[i].printinfos();
        document.getElementById('insert_text').insertAdjacentHTML(person, "beforeend");
        console.log(person);
     }

Also don't forget to declare i inside the loop.

D. Pardal
  • 6,173
  • 1
  • 17
  • 37