so im trying to save colour selector to local storage so it will save the users selection after refreshing the page
this is a snippet of my code so far, if i remove the localstorage code from the script it will change colours but wont save the selection.
document.addEventListener('click', (e) => {
const colorOption = e.target.closest('.color-option');
if (!colorOption) return;
// unselect currently selected color options
document.querySelectorAll('.color-option').forEach(colorOption => colorOption.classList.remove('is-selected'));
colorOption.classList.add('is-selected');
const color = colorOption.dataset.color;
let root = document.documentElement;
root.style.setProperty('--primary-color', color);
localStorage.setItem(".color-option", "--primary-color");
localStorage.getItem("--primary-color");
});
body {
background-color: var(--primary-color);
}
.color-option {
height:35px;
width: 35px;
list-style: none;
border-radius: 4px;
margin: 7px;
transition: .2s;
cursor: pointer;
&:hover {
box-shadow: 0 0 0 5px rgba(0,0,0,.2);
}
&.is-selected {
transform: scale(1.1);
box-shadow: 0 0 0 5px rgba(0,0,0,.2);
}
}
.color-option:nth-child(1) { background: #3485fd }
.color-option:nth-child(2) { background: #002C5F }
.color-option:nth-child(3) { background: #00AFD8 }
.color-option:nth-child(4) { background: #5B1F69 }
.color-option:nth-child(5) { background: #FF5F1F }
.color-option:nth-child(6) { background: #ff00e2 }
<body>
<ul class="color-grid">
<li class="color-option is-selected" data-color="#3485fd"></li>
<li class="color-option" data-color="#002C5F"></li>
<li class="color-option" data-color="#00AFD8"></li>
<li class="color-option" data-color="#5B1F69"></li>
<li class="color-option" data-color="#FF5F1F"></li>
<li class="color-option" data-color="#ff00e2"></li>
</ul>
</body>
can't quite figure out what im doing wrong hopefully someone can help