I've been trying to make simple to-do list to learn javascript and I have been able to add and display a task but I can't find a way to delete it. I have created a remove button but I can't make work, nothing happens when clicked. So any help would be great, thanks !
function handleSubmit(event){
event.preventDefault();
let value = getInputValue();
if(value !== false){
addToDom(value);
eraseInput();
}
}
const form = document.querySelector("#todo-list-form");
form.addEventListener('submit', handleSubmit);
function getInputValue() {
const input = document.querySelector("#todo-input");
let value = input.value;
value = value.trim();
if (value === '') {
alert("You can not submit an empty field");
return false;
}
else {
return value;
}
}
function addToDom(value) {
const list = document.querySelector("#list");
const removeButton = document.createElement("button");
removeButton.innerHTML = 'remove';
removeButton.classList.add("complete-btn");
list.appendChild(removeButton);
list.innerHTML += "<li>" + value + "</li>";
console.log(list);
removeButton.addEventListener('click', removeItem)
}
function removeItem(event){
event.parentElement.remove();
}
function eraseInput() {
const input = document.querySelector("#todo-input");
input.value = "";
input.focus();
}