title: Using localStorage to Remember if User Already Voted
body: <p>I'm trying to use <code>localStorage</code> to remember if the user has already voted. I have 5 buttons — all with a unique ID to help me keep track of things.</p>
  
  <p>When a user clicks on one of these buttons (e.g., <code>button-1</code>), I store the ID of that button with a value. So in <code>localStorage</code>, it looks something like this: <code>key: button-1, value: clicked</code>.</p>
  
  <p>If the user has already clicked (voted) on that button, it needs to display a message, something like "Thank you for your vote." Otherwise it should keep that button active.</p>
  
  <p>I'm struggling to do this systematically if I have multiple buttons. Do I store a separate key for each button in <code>localStorage</code>? Do I append them under one key? I am not sure.</p>
  
  <p>My JSFiddle is here as an example with 3 buttons <strong><a href="http://jsfiddle.net/d8kt69rp" rel="nofollow">http://jsfiddle.net/d8kt69rp</a></strong></p>
  
  <hr>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div id="button-1"&gt;
    &lt;button value="yes" onclick="recordFeedback(1, this);"&gt;Button 1&lt;/button&gt;
  &lt;/div&gt;
  &lt;div id="button-2"&gt;
    &lt;button value="yes" onclick="recordFeedback(2, this);"&gt;Button 2&lt;/button&gt;
  &lt;/div&gt;
  &lt;div id="button-3"&gt;
    &lt;button value="yes" onclick="recordFeedback(3, this);"&gt;Button 3&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>// If user has already voted, just display them a 'thanks' message
  if (localStorage.getItem('button-1')) {
      var div = document.getElementById('button-1');
    div.innerHTML = 'Thank for your feedback';
  }
  
  // Record user feedback based on the button they clicked
  function recordFeedback(id, response) {
      userResponse = response.value;
      var div = document.getElementById('button-' + id);
    if (userResponse === 'yes') {
       div.innerHTML = 'Thanks for your feedback.';
       console.log('button-' + id + ' was clicked.');
       localStorage.setItem('button-' +id, 'clicked');
    }
  }
  </code></pre>