Trying to do a addToWishlist
function so item can be saved for later viewing, when I save the boolean
value true/false
in the localStorage
its toggling but not the .addClass
jQuery. I'm saving it to localStorage
so if user refresh the page it still holds the items they've saved.
How can I fix the addClass
toggle properly, based on the value saved in localStorage true/false
?
<button onclick="wishList()" class="btn btn-default wishlist"><i class="fa fa-heart" aria-hidden="true"></i> Add to wishlist</button>
var wishlistItems = localStorage.getItem('wishlists');
var addToWishlist = false;
function wishList() {
addToWishlist = !addToWishlist;
localStorage.setItem('wishlists', addToWishlist);
if(wishlistItems === false) {
$(this).find('.fa').removeClass('add-to-wishlist');
}
$(this).find('.fa').addClass('add-to-wishlist');
}