I am working on a simple to do list app and I want to add a function that deletes checked items. Below is the code I have so far.
function onReady() {
const addToDoForm = document.getElementById('addToDoForm');
const newToDoText = document.getElementById('newToDoText');
const toDoList = document.getElementById('toDoList');
addToDoForm.addEventListener('submit', () => {
event.preventDefault();
// get the text
let title = newToDoText.value;
// create a new li
let newLi = document.createElement('li');
// create a new input
let checkbox = document.createElement('input');
// set the input's type to checkbox
checkbox.type = "checkbox";
// set the title
newLi.textContent = title;
// attach the checkbox to the li
newLi.appendChild(checkbox);
// attach the li to the ul
toDoList.appendChild(newLi);
//empty the input
newToDoText.value = '';
});
}
var checkbox = document.querySelector("input[name=checkbox]");
checkbox.addEventListener( 'change', function() {
if(this.checked) {
// Checkbox is checked..
} else {
// Checkbox is not checked..
}
});
window.onload = function() {
onReady();
};
Before I added the var checkbox, items were added to list. Now no items appear on list. What am I missing?
Aucun commentaire:
Enregistrer un commentaire