This jQuery works great to change the background color of all my divs with the same class (userNumber1), when I check its checkbox, but I need it to also save these changes to localStorage, in order to be there each new time the page is loaded.
After searching for a week in SO, I've tried several different options I've found, but none works properly. While in most cases I can still change the back ground color, some of them save only the checked checkbox but not the background color, other ones do the opposite, yet the most of them save none of both to localStorage.
As I'm not an expert at all, I really don't know what else to do now.
This my jQuery function:
jQuery(document).ready(function($) {
$('#option1').on('change', function() {
if ($(this).is(':checked')) {
$(".userNumber1").css('background-color', "#a7ddff");
} else {
$(".userNumber1").css('background-color', "#ffffff");
}
})
})
and this one is my HTML code:
<div class="userNumber1"><input type="checkbox" id="option1"><label for="option1"></label></div>
I'm totally open to any different approach, as long as I can save the new background color and the checked/unchecked checkbox to localStorage.
Thank you in advance for your kind support.