title: How to loop through ids with same prefix
body: <p>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.</p>
  
  <pre><code>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');
  
  }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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');
  
  }
  </code></pre>
  
  <p>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.</p>