I am trying to learn JS by creating simple todolist, and have problem to delete the list
function addTodo(e) {
e.preventDefault()
const val = document.getElementById('list-input').value;
const li = createNewTask(val);
ul.appendChild(li);
resetForm.reset();
return ul
}
const createNewTask = function (val) {
const listItem = document.createElement('li');
const deleteBtn = document.createElement('button')
const valNode = document.createTextNode(val)
//Modified each element
deleteBtn.innerText = 'Delete';
deleteBtn.className = 'delete';
//append each child
listItem.appendChild(valNode)
listItem.appendChild(deleteBtn)
return listItem;
}
I manage to add new Todo list to my simple app, but I can't figure it out how to delete it.
you can see it in action through this link http://jsbin.com/qunefum/edit?html,js,output
have watched and read some documentations, but can't figure out how to point to the correct element, also all the example seems too complicated