/    Sign up×
Community /Pin to ProfileBookmark

add/remove item to LocalStorage & Display in html – plain javacript

I am kind of behind in school project schedule, and I got this task where I am struggling with and wish for a small help how to do it.

-So I gonna use strapi to create my own api. – Which I know how to.
-Make html for each item where i will be displaying 3 properties for each. – Which is fine, I know how to.
-There is going to be a icon where clicking the icon, will store the items in local storrage, while also display it in a “favorite page” – which is the part I am struggling with

So theres is gonna be a “Homepage” and a “Favorite” html page.

“”Favorite page:
This page should fetch the array of items stored in localStorage and display them or display a message that there are no items.
There should be a “Clear all” button that clears localStorage (or just a specific key in localStorage) and reloads the display. Don’t reload the page, just redraw the HTML.””

So does anyone know and could show me direction to what to look at to be able to solve this?

So what I am planning to do is product card, it fetching image, title, description, price and a heart icon, clicking the heart icon should add the card/product to local storage and display it in favorite page, clicking the heart again should remove the card/product from local storage.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@boohooOct 21.2021 — What exactly is the problem for you?
Copy linkTweet thisAlerts:
@daveyerwinOct 21.2021 — > @CarbonDRFT#1638407 said ...

> This page should fetch the array of items stored in localStorage and display them or display a message that there are no items.

> There should be a “Clear all” button that clears localStorage (or just a specific key in localStorage) and reloads the display.



____________________________________________________

It seems to me that you first need to 'set' localStorage

https://www.w3schools.com/jsref/prop_win_localstorage.asp
Copy linkTweet thisAlerts:
@clefayomideOct 27.2021 — You have to set an onClick event on the icon. Once it's clicked, it sets the local storage. localStorage.setItem(itemIdentifier, theItem)

And on the favorite page you can use the onload function to get items from the localStorage window.onload = localStorage.getItem(identifier) you can then display the items in a nice GUI
×

Success!

Help @CarbonDRFT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...