I'm trying to delete a particular item from the local storage on clicking on a button inside one of the displayed divs.
When I press the button, the needed div is deleted, but I can't get it removed from local storage, so when the page's refreshed it appears again. Local storage Key: watchList Value: ["tt0089880","tt0489270","tt0387564","tt0432348","tt1201607"]
fetch(`https://www.omdbapi.com/?i=${movies[i]}&apikey=123`)
.then((res) => res.json())
.then((movie) => {
containerList.innerHTML += `<div class="movie">})
//here I try to delete it from the local storage, but it doesn't work
containerList.addEventListener("click", (e) => {
const tgt = e.target.closest("button");
if (e.target.matches(".watchlist")) {
tgt.closest(".movie").remove();
localStorage.removeItem()
}
})
I don't know how to connect the needed index of the Local Storage array to a particular DIV.
The full code is here: https://codepen.io/btb8293/pen/KKoLOmZ