inside a loop I'm creating multiple checkboxes using
checkbox = document.createElement("input");
I tried adding this inside the loop but it doesn't help
checkbox.setAttribute("onchange", function toggle() {});
I need some type of listener outside the loop to check which checkbox was changed so I can change the value inside localStorage of a boolean variable.
checkboxes = document.querySelectorAll(".checkbox");
checkboxes[0].addEventListener("change", function toggle() {
lists[checkboxes[0].value].tasks[checkboxes[0].id].completed = this.checked;
localStorage.setItem("lists", JSON.stringify(lists));
});
I want something like this without having to give the checkboxes array a static index.
Aucun commentaire:
Enregistrer un commentaire