There are many ways to do this. Here is one of them.
The first function checks if any values ββhave been previously saved in localstorage and sets the text of the link text accordingly. This is done every time the page is refreshed / reopened.
The second function saves / removes the key in localstorage .
I used the text <li> as the key to search (for example, "html5", "jQuery", etc.). You can choose a prefix with a namespace (for example, localStorage.getItem('myNamespace' + favs) ), using the same thing to get the value, to keep it separate from other values ββin localstorage , if you wish.
var addFav = "Add to Fav"; var remFav = "Remove";
<ul class="lists"> <li>Html5 <a href="#"></a></li> <li>Jquery <a href="#"></a></li> <li>Php <a href="#"></a></li> <li>Photoshop <a href="#"></a></li> </ul>
External demo: https://jsfiddle.net/n4byghd3/1/
To test the demo, select an item or two, and then close and reopen the page (or just click "Run again").
source share