Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Dark mode gets turned off on refreshing a page
function darkMode() {
  var element = document.body;
  var content = document.getElementById("DarkModetext");
  element.className = "darkmode11"
  content.innerText = "Dark Mode is ON"
  content.style.color = "white"
}
function lightMode() {
  var element = document.body
  var content = document.getElementById("DarkModetext")
  content.innerText = "Dark Mode is OFF"
  element.className = "lightmode11"
  content.style.color = "black"
}

//I have made two function one is for darkmode and another is for light mode the problem is when i turn on the dark mode and refresh the page the dark mode get turned off

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You have to save mode setting somewhere like cookies or localStorage. Code below does this for you hope this is helpful. script type='module' means this script runs before page load so page doesnt flash white to black.

    <script type="module">
if(localStorage.getItem('mode') == 'dark'){
    darkmode();
    }

    function darkMode() {
      localStorage.setItem("mode","dark");
      var element = document.body;
      var content = document.getElementById("DarkModetext");
      element.className = "darkmode11"
      content.innerText = "Dark Mode is ON"
      content.style.color = "white"
    }
    function lightMode() {
      localStorage.setItem("mode","light");
      var element = document.body
      var content = document.getElementById("DarkModetext")
      content.innerText = "Dark Mode is OFF"
      element.className = "lightmode11"
      content.style.color = "black"
    }
</script>
about 4 years ago · Juan Pablo Isaza Report

0

You can easily store that dark mode is on or not in localStorage.

localStorage.setItem("theme", "dark");

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!