I'm trying to populate the contents of an array with the HTML from 5 different div elements using a loop. I can't get the for loop to work correctly. Any ideas?
The HTML:
<div id="person0">John</div>
<div id="person1">Kathleen</div>
<div id="person2">Cynthia</div>
<div id="person3">Eric</div>
<div id="person4">Jay</div>
<div style="width: 600px; margin: auto; padding: 15px; border: 1px solid gray; font-family: sans-serif;">
<h1>The People</h1>
<div id="result"></div>
</div>
The Javascript:
function pageLoaded(){
var list = "<ul>";
var myArray = new Array();
for(i=0; i<6; i++){
var person = "person";
var personNumber = "" + i.toString();
var divId = person.concat(personNumber);
myArray[i] = document.getElementById(divId).innerHTML;
list +="<li>"+myArray[i]+"</li>";
}
list +="</ul>";
document.getElementById("result").innerHTML=list;
}