I am making a to-do list and when you click on a item it get the class "checked". How do i keep the state of the checked items? If I refresh the page now everything wil return to its normal state without the checked class.
I am looking for the right way to include LocalStorage in this. How can I store the checked class?
<ul id="myUL">
<?php require_once "includes/todo-data.php";
for($i = 0; $i < count($todo); $i++) { ?>
<li>
<?= $todo[$i]['bericht']; ?> <br> rollen: <?= $todo[$i]['rol']; ?>
<a class="close" href="includes/delete.php?id=<?= $todo[$i]['id'] ?>">×</a>
</li>
<?php } ?>
</ul>
<script>
// Add a "checked" symbol when clicking on a list item
if (typeof(Storage) !== "undefined") {
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if (ev.target.tagName === 'LI') {
ev.target.classList.toggle('checked');
// Store
localStorage.setItem();
// Retrieve
document.getElementById("myUL").innerHTML = localStorage.getItem();
}
}, false);
} else {
document.getElementById("myUL").innerHTML = "Sorry, your browser does not support Web Storage...";
}
</script>