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

407
Views
How to save custom color on localStorage jquery?

I` have a function in jquery witch allow users to change background color of site. But if they refresh the page background-color go to default. How can i use LocalStorage with this jquery function

sessionStorage.setItem("bg_color", "#000");
let personName = sessionStorage.getItem("bg_color");

$(document).ready(function() {
    $('.dark__mode').click(function() {
        $('#headerCustomColor').css("background-color", personName);
        $('#TogleBarWi').css("color", "#fff");
        $('.custom_color_link').css("color", "#fff");
    });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

//You have to check if there is a certain background
// If there is a background color use it else use default
let background = localStorage.getItem("background") ? localStorage.getItem("background") : "#FFF";

// Change header on document loading the background color based on localStorage
$('#headerCustomColor').css("background-color", background);

// On click
$('.dark__mode').click(function() {
    // Set the variable background to custom
    background = "#383838";
    // Set localStorage bg color to custom 
    // This is to enable on refresh so the new bg is set.
    localStorage.setItem("background", background);
    
    // Recolor the header after the click
    $('#headerCustomColor').css("background-color", background);

});
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!