I am looking to implement a favorites feature on my website using HTML, CSS, JavaScript, and JSON. The JSON file is loaded through AJAX and users can search for devices to add to their favorites using sessionStorage and localStorage. However, I'm facing an issue where adding a new device overrides the existing one. I'm considering using an IF statement to check if there is already an ID present before adding a new one, but I'm unsure of how to proceed...
Here are some code samples:
$(document).on('click', '.productfavourite', function(event) {
// Get the ID of the clicked element as product fave
productFave = event.target.id;
localStorage.setItem('productFave', productFave);
console.log(productFave);
window.location="favourites.html";
});