How to get document.querySelectorAll to store members of a class in sessionStorage or localStorage and display them on another page?

As programming isn’t my forte and I’m logically-handicapped, I’ve been trying to get this code to work for the past 3 days and have hit a proverbial wall. What I’m trying to do is create JS code that will retrieve article blurbs within a certain topic (via class identifiers) and have them automatically display on a separate topic page (e.g. if the article is about a widget, the blurb also shows up on the Widget page). Thank you in advance for any help or suggestions you can provide!

Here’s the code that works as long as you only need to select one item per topic (not the case):

//

Here’s my revised code using document.querySelectorAll. It’s not working (disappears into a huge black hole). I’ve tried adding a few wrinkles, such as using the Array.from property (var EVArray = Array.from(EV)), but no luck:

Hello!

What you are looking for are the localstorage,setitem() and get.item() methods.

I got from your post that you want to store multiple values at once.
You need to use JSON in this case, it would be beyond the scope of my reply.

This article will help you get into the topic:

Hope it works out.

Thank you for the reply Daniel. I’ve added an Array.from statement and JSON.stringify, but unfortunately it’s still not working. Probably am just not figuring out how to assign the values in the array to innerHTML, but really not sure.

The best way to help is to see your code live.

Get a CodePen account (if you don’t have one already), put your code in there and share the link in this or another topic. Then we can help you debug.

Thank you for the kind offer. Believe it or not though, after posting here, I asked ChatGPT to convert my existing code and what I got back works like a charm!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.