I am facing an issue while trying to display an array of items in a list. The problem is that when I click submit, it adds all the array items to each list item instead of adding one item each time.
Here is the link to JSFIDDLE: https://jsfiddle.net/b7Lwbrof/
Thank you!
var itemList = [];
var container = document.getElementById('container');
// On click
document.getElementById('submit').addEventListener("click", function(){
var itemValue = document.getElementById('itemValue').value;
// Push to array
itemList.push(itemValue);
// Append to List
for(i=0; i<itemList.length; i++) {
var items = document.createElement("li");
document.getElementById('container').appendChild(items);
items.innerHTML = itemList[i];
}
})