Clicking on the list from down should save the item to an array in local storage.
$(document).ready(function() {
$( 'ul.namelist>li' ).on( "click", function() {
var items = [];
items.push( $( this ).text() );
localStorage.setItem("items",items);
});
})
HTML
<ul class="namelist">
<li>John</li>
<li>Leena</li>
<li>Paul</li>
<li>Vaughn</li>
<li>Aneel</li>
<li>Jason</li>
</ul>
This code stores only last clicked name in the array where as I am trying to store all clicks in it as [John,Paul,Leena] etc. Please help.
localStoragecan only store strings. TrylocalStorage.setItem('items', JSON.stringify(items)). Of course, each time you click an<li>, you will only ever store an array of length1