Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Forum » x-Forum » Question

How do you save a change to CSS, using Local Storage?

I followed a YouTube tutorial to create a button on my website – when you click the button, the background color changes. However, this change does not remain when the page is refreshed or when another page is visited. I have tried to save this using LocalStorage, but have not been able to figure it out. I am hoping to have some help figuring out how to use Local Store to save this change to my CSS. Thank you!

This is my Javascript:


var color = ["#ad9ea1", "#8e96a3", "#94a899", "#cfc5b6", "#91919c", "#b3b4b5"];
var i = 0;
document.querySelector("button").addEventListener("click", function() {
  i = 0 <= color.length ? ++i : 0;
  document.querySelector(".caro").style.background = color[i];
  if (i == 5) {
    i = 0;
  }
})

Posted by nh826826 2020-12-07 00:23:56

No Ans Posted

Please login to comment

Log In


Ask New Question