I've run into an issue trying to incorporate LocalStorage with the buttons that change colors as themes in JavaScript. I'm new to coding and eager to add this feature to my personal blog.
$(document).ready(function () {
$(".header--theme-button").on("click", function() {
var primaryColor = localStorage.getItem("--theme-primary");
var secondaryColor = localStorage.getItem("--theme-primary");
var primaryColor = $(this).css("--theme-primary");
var secondaryColor = $(this).css("--theme-secondary");
$().change(function () {
var primaryColor = $(this).val();
$('.header--theme-button').css("--theme-primary");
localStorage.setItem("--theme-primary", primaryColor);
var secondaryColor = $(this).val();
$('.header--theme-button').css("--theme-secondary");
localStorage.setItem("--theme-primary", secondaryColor);
});
$(".header--theme-button").removeClass("active");
$(this).addClass("active");
$(document.body).css("--primary-color", primaryColor);
$(document.body).css("--secondary-color", secondaryColor);
});
});