title: Why is my localstorage for my JS button not working?
body: <p>I'm not sure why my localstorage isn't working. When the page loads, it loads up the function stored(), which should be the stored value for my toggle function, which changes the page from light to dark.</p>
  <p><strong>HTML:</strong></p>
  <pre><code>&lt;body onload=&quot;stored()&quot;&gt;
  &lt;label for=&quot;ID_HERE&quot; class=&quot;toggle-switchy&quot; &gt;
      &lt;input checked type=&quot;checkbox&quot; name=&quot;server&quot; id=&quot;ID_HERE&quot;&gt;
          &lt;span class=&quot;toggle&quot; onclick=&quot;toggle()&quot; id=&quot;saveDarkLight&quot;&gt;&lt;/span&gt;
        &lt;span class=&quot;switch&quot;&gt;&lt;/span&gt;
      &lt;/span&gt;
  &lt;/label&gt;
  </code></pre>
  <p><strong>(Removed old javascript file as it did not let me post too much code)</strong></p>
  <p><strong>Updated HTML:</strong></p>
  <pre><code>&lt;label for=&quot;ID_HERE&quot; class=&quot;toggle-switchy&quot; &gt;
      &lt;input checked onclick=&quot;toggle()&quot; type=&quot;checkbox&quot; name=&quot;server&quot; id=&quot;ID_HERE&quot;&gt;
          &lt;span class=&quot;toggle&quot; id=&quot;saveDarkLight&quot;&gt;&lt;/span&gt;
        &lt;span class=&quot;switch&quot;&gt;&lt;/span&gt;
      &lt;/span&gt;
  &lt;/label&gt;
  </code></pre>
  <p><strong>Updated JS:</strong></p>
  <pre><code>function stored() {
      var storedValue = localStorage.getItem(&quot;server&quot;);
      if(storedValue){
        lightmode()
        document.getElementById(&quot;ID_HERE&quot;).checked = true;
      }else{
         darkmode()
         document.getElementById(&quot;ID_HERE&quot;).checked = false;
      }
    }
  
  
    function toggle() {
      if(document.getElementById(&quot;ID_HERE&quot;).checked) {
        lightmode()
        var input = document.getElementById(&quot;ID_HERE&quot;);
        localStorage.setItem(&quot;server&quot;, input.checked);
      }
      else {
          darkmode()
          var input = document.getElementById(&quot;ID_HERE&quot;);
          localStorage.setItem(&quot;server&quot;, input.checked);
      }
  }
  </code></pre>