Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:59:27+00:00 2026-06-13T10:59:27+00:00

I have this section of code that saves a list item on click to

  • 0

I have this section of code that saves a list item on click to localStorage based on the list item’s id number. On a different page I am then able to load whatever list items were saved.

var save1075 = $('#store-1075').get(0);
$('#store-1075').on('click', function () { 
    var storeStorageKey1075 = $(this).attr('id'); 
    localStorage.setItem('storeStorageKey1075', $(this).attr('id'));
    localStorage.setItem('storeStorageKey1075', this.innerHTML);
});

if ( localStorage.getItem('storeStorageKey1075') ) {
save1075.innerHTML = localStorage.getItem('storeStorageKey1075'); 
}

var storeStorageKey1075 = $(this).attr('id');
    if ( localStorage.getItem('storeStorageKey1075') ) {
    storeStorageKey1075 = localStorage.getItem('storeStorageKey1075');

}

Right now I have to repeat that chunk of code for every individual id number and I’m trying to instead make the id number a variable that loops through all possible id numbers when clicked but only saves the id of that specific one. Maybe something along the lines of this:

var id = //some sort of loop or array of possible ids.
var save = $('#store-'+id).get(0);
$('#store-'+id).on('click', function () { 
    var storeStorageKey = $(this).attr('id'); 
    localStorage.setItem('storeStorageKey', $(this).attr('id'));
    localStorage.setItem('storeStorageKey', this.innerHTML);
});

if ( localStorage.getItem('storeStorageKey') ) {
save.innerHTML = localStorage.getItem('storeStorageKey'); 
}

var storeStorageKey = $(this).attr('id');
    if ( localStorage.getItem('storeStorageKey') ) {
    storeStorageKey = localStorage.getItem('storeStorageKey');

}

Each of the list items has the same prefix of “store-” and the numbers are in no specific order but randomly generated each time a new store location is created.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:59:28+00:00Added an answer on June 13, 2026 at 10:59 am

    The obvious thing to do is to add a class but you could also:

    var elems = $( "[id^='store']")
    
    elems.on( "click", function() {//Save html on click
        localStorage.setItem( this.id, this.innerHTML );
    });
    
        //Retrieve html
    elems.each( function() {
        var html = localStorage.getItem( this.id );
    
        if( html ) {
            $(this).html( html );
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div like this <section class=item_container> <article class=item> <h2>Page Title</h2> <p><a class=delete_page
hey there guys and girls i have this code that saves json as a
I have this view (DetailsContainer, first class in code section of this question) with
This section has me thoroughly confused. I have an example problem that I am
Interesting situation. I have a section of code that creates several ZipOutputStreams. As a
I have this app of mine that contains a section that will allow the
I have the following code that takes a username and a password and then
I have a file like this ### SECTION 1 ### data data data data
I have this line in the declarations section: Private filePath As String And something
I've just started with this section of the tutorial. I only have a basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.