I'm struggling with the following code snippet:
<div class="places-item">
<div class="places-item-img"></div>
<div class="places-item-header">
<h2>Machu Picchu, Peru</h2>
<div class="places-item-header-add"><svg xmlns='http://www.w3.org/2000/svg' width='512' height='512' viewBox='0 0 512 512'><path d='M352,48H160a48,48,0,0,0-48,48V464L256,336,400,464V96A48,48,0,0,0,352,48Z' style='fill:transparent;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/></svg></div>
</div>
</div>
<div class="places-item">
<div class="places-item-img"></div>
<div class="places-item-header">
<h2>Ciucaș Peak, Romania</h2>
<div class="places-item-header-add"><svg xmlns='http://www.w3.org/2000/svg' width='512' height='512' viewBox='0 0 512 512'><path d='M352,48H160a48,48,0,0,0-48,48V464L256,336,400,464V96A48,48,0,0,0,352,48Z' style='fill:transparent;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/></svg></div>
</div>
</div>
.places-item {
width: 100%;
}
.places-item-img {
width: 100%;
height: 350px;
background-color: cyan;
}
.places-item-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1em 0;
}
.places-item-header h2 {
font-size: 24px;
max-width: calc(100% - 38px);
}
.places-item-header-add {
width: 28px;
height: 28px;
cursor: pointer;
}
.places-item-header-add svg {
width: 100%;
height: 100%;
}
.places-item-header-add.added svg path {
fill: #000 !important;
}
var addBtn = document.querySelectorAll('.places-item-header-add');
for(i=0;i<addBtn.length;++i)addBtn[i].addEventListener('click',function(){
this.classList.toggle('added');
});
After clicking on the icon, it should turn black. How can I ensure that the clicked icon remains black even after a page refresh? Would using localStorage be an ideal solution in this case?