going somewhere.

This commit is contained in:
didier amyot committed 2024-01-27 06:54:28 -05:00
1 parent 1569c514d4
commit 8a72eec139
2 files changed
+20

No files matched your search

+2
View File
@@ -18,6 +18,8 @@
</ul> </ul>
</div> </div>
<button id="effacer">Effacer</button>
<script src="main.js" type="module"></script> <script src="main.js" type="module"></script>
</body> </body>
</html> </html>
+18
View File
@@ -17,6 +17,15 @@ function addToLocalStorage(value) {
localStorage.setItem("elm", JSON.stringify(listeStockage)); localStorage.setItem("elm", JSON.stringify(listeStockage));
} }
function clear(){
localStorage.removeItem("elm");
// const listElement = document.getElementById("list1");
// const children = new Array(listElement.children);
// for(const child of children){
// listElement.removeChild(child);
// }
}
function getListFromLocalStorage() { function getListFromLocalStorage() {
let serialized = localStorage.getItem("elm"); let serialized = localStorage.getItem("elm");
if(!serialized){ if(!serialized){
@@ -25,4 +34,13 @@ function getListFromLocalStorage() {
return JSON.parse(serialized); return JSON.parse(serialized);
} }
function initializeList(){
const items = getListFromLocalStorage();
for(const item of items){
addItemInList(item);
}
}
document.getElementById("exo1").addEventListener("click", click); document.getElementById("exo1").addEventListener("click", click);
document.getElementById("effacer").addEventListener("click", clear);
initializeList();