So I'm creating a note taking app that persists the notes to local storage. When reloading the page, it is supposed to load those notes and create a list element with each one. Problem is that it only creates the last item. I know the strings are getting pushed to local storage and I know the forEach is cycling through them as expected, so the problem must be in how the DOM is manipulated. Here's the code.
For Each:
notes.forEach(function(index){
listText.innerHTML = index;
listDiv.appendChild(listText);
li.appendChild(listDiv);
li.appendChild(delButton);
document.querySelector("ul").appendChild(li);
});
DOM Variables:
// UI VARIABLES
const li = document.createElement("li");
const listDiv = document.createElement("div");
const listText = document.createElement("div");
listDiv.className = "listDiv";
listText.className = "listText";
// DELETE BUTTON
const delButton = document.createElement("button");
delButton.innerHTML = "X";
delButton.className = "delButton";