I am currently working on developing a web application where clicking a button saves its ID to local storage and changes its style. However, I am facing an issue where the ID of the last clicked button replaces the ID of the previously clicked button in local storage. Here is a snippet of my code:
$(document).ready(function(){
$("li a").click(function(){
$("li a").removeClass('active');
$(this).addClass('active');
localStorage.setItem('active', $(this).html())
});
var active = localStorage.getItem('active');
$("li a").each(function(index){
if($(this).html() == active) {
$(this).addClass('active');
}
});
});
Your help in resolving this issue would be greatly appreciated. Thank you.