I'm not quite sure how to phrase my main question in the title but I'll try my best to explain it down here. I'm creating a javascript app that takes user input and then adds it as a list item into a list. I want each list item to have a button that will delete the corresponding list item when pressed. Here is my code:
function addToList(){
removeBtn = document.createElement('button');
listItem = document.createElement('li');
listItem.textContent = row[0]+ ' $' + row[1]+ ' ' + row[2]+' ';
removeBtn.addEventListener('click', removeLi);
listItem.appendChild(removeBtn);
list.append(listItem);
}
I've tried a couple things but I just dont know what to put in my removeLI function that will delete the parent <li> of the button that got clicked. Any help would be much appreciated
const,letorvarin front of your variable declarations. Using global variables like this is going to lead to problems