title: Can I affect CSS with JavaScript?
body: <p>I'm new to all this so sorry if it's a stupid question. Basically, I have my CSS colours set up as three :root functions and the JavaScript has everything done for a light mode/dark mode toggle but now I want it so that when dark mode is true the colours in CSS change. Is there a way of doing this? (Even if it means duplicating the CSS and making the second one have the dark mode colours with JS choosing which file to choose based on the true or false statement of the toggle in HTML?</p>
  
  <p>HTML/JS:</p>
  
  <pre><code>&lt;li&gt;
      &lt;label&gt;Night mode&lt;/label&gt;
      &lt;br&gt;        
      &lt;input type="checkbox" name="Nightmode" class="switch" id="nightModeCheckBox"&gt;
      &lt;script&gt;
          var nmbc = document.getElementById("nightModeCheckBox").checked;
          if (localStorage.getItem("nightMode") == "true"){
              document.getElementById("nightModeCheckBox").checked = true;
          }
      &lt;/script&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;button onclick="settingsSave()" class="save"&gt;Save&lt;/button&gt;
      &lt;p id="saveText"&gt;&lt;/p&gt;
      &lt;script&gt;
          function settingsSave() {
          var nmbc = document.getElementById("nightModeCheckBox").checked;
          if (typeof(Storage) !== "undefined") {
          localStorage.setItem("nightMode", nmbc);
          alert(localStorage.getItem("nightMode"));
          } else {
          alert("It seems your browser doesn't support local storage. Try updating it or using a different browser.");
          }
          }
          console.log(nmbc)
      &lt;/script&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>:root{
      --color1: White;
  }
  
  :root{
      --color2: rgb(230, 230, 230);
  }
  
  :root{
      --colorText: black;
  }
  </code></pre>