Skip to content Skip to sidebar Skip to footer

Removing Items From The Localstorage

I'm trying to remove the individual items from the localStorage. I'm using localStorage for storing selected list items in the listview. I attached the checkboxes for removing the

Solution 1:

try removing items like this, removing local storage items by their key values

//syntax is localStorage.removeItem('keyName');//so if your key name is checked                  localStorage.removeItem('checked');

See this Link for reading about local storage.

Solution 2:

I think the problem is in this part:

$("#delete").on('click', function() {
            var checked = $('#add #check:checkbox:checked');
            var url = localStorage.key(checked);
            localStorage.removeItem(url);
            $("#favoritesList").listview('refresh');
});

you are not using correct key for deleting and its because you are using :

var url = localStorage.key(checked);

and checked==[Object]==1 so you are pointing to localStorage.key(1)


for solving this problem you can both use key=localStorage.key(some);localStorage.removeItem(key); and localStorage.removeItem(some); but the important part is that you should match 'an index(first way)' or a 'key value(the second way)' for each checkbox and I can help you if I have the complete code (I think still there are some part of HTML or codes that are related)(also it would be so good if you put a fiddle of your codes)

Solution 3:

localstorage.removeItem() wont work as expected. I had faced the same problem while trying to handle the localstorage items.

A work-around for this problem was to set the local storage item to null. It served my purpose.

For example if you have a localStorage item named test then to clear the item use :

localStorage.setItem("test", "");

Although this may not be the correct way, i had gone bonkers over this issue and the above one served my purpose.

Solution 4:

Just use localStorage.clear();

Post a Comment for "Removing Items From The Localstorage"