I work on a project where I use the Localstorage function along with clone and it works fine
but the problem how to add number increment in .count class like I click on save1 save2 save3 then total number count shown like <div class='count'>3</div>
Here is Demo of my code JsFiddle Demo
here is my code below where I try to add .count system along with all append elements but I am not able to add
$('.item-all .item-save').click(function() {
$(this).toggleClass('productad')
window.localStorage.setItem('test' + this.dataset.id, $(this).hasClass('productad'));
});
$('.item-all .item-save').each(function() {
var id = 'test' + this.dataset.id;
if (localStorage.getItem(id) && localStorage.getItem(id) == "true") {
$(this).addClass('productad');
$(this).clone().appendTo('.item-append');
}
});
$(".item-all .item-save").click(function() {
var existing = $(".item-append [data-id=" + $(this).data("id") + "]");
if (existing.length > 0)
existing.remove();
else
$(this).clone().appendTo('.item-append');
});
$(".close").click(function() {
localStorage.removeItem("'test' + this.dataset.id"), $(this).removeClass('productad');
});
.item-save {
position: relative;
display: block;
font-size: 14px;
width:80px;
margin: 5px;
padding: 5px;
background: #a5a5a5;
text-align: center;
cursor: pointer;
}
.item-all{display:flex}
.productad{background:red;color:#eee}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='item-all'>
<div class='item-save' data-id='123'>
Save1
</div>
<div class='item-save' data-id='124'>
Save2
</div>
<div class='item-save' data-id='125'>
Save3
</div>
<div class='item-save' data-id='126'>
save4
</div>
</div>
<hr/>
<div class='item-append'>
<div class='count'>3</div>
</div>
Any kind of help or suggestions is highly appreciated