4

I'm trying to remove item from localStorage in javasscript but it doesn't work.

It only works manually for the sequence of the following events

Right click --> Inspect element --> Resources --> localStorage --> Right click --> Delete 

I tried:

localStorage.clear(); 

and

localStorage.removeItem(key); // the key is the link of the page and 
                              // the value is the selected word in the page 

and both didn't work, I can save item using localStorage.setItem(key, vaule) and get items from localStorage using localStorage.getItem(key) but I can't remove them.

hygull
  • 8,464
  • 2
  • 43
  • 52
elianore
  • 319
  • 2
  • 5
  • 9
  • 1
    a code example that isn't working would help us help you. – BLSully Feb 13 '13 at 22:26
  • this is the only thing is not working , i want to remove the old values and put another each time i use this "function" so everything is perfect unless localStorage.clear(), it won't remove anything – elianore Feb 13 '13 at 22:54

2 Answers2

4

what your looking for is this:

deleter void removeItem(DOMString key);

You could implement this like so:

localStorage.removeItem(key)

Everything about local storage can be found here on the W3 html5 spec for web storage.

You may find this document more helpful as it goes into more explanation.

*Local storage is not a finished spec and these could change.

Ryan
  • 5,644
  • 3
  • 38
  • 66
  • the first one after it i can't save values anymore. and the second one didn't work. in my code i want to remove the values to set another value. thank u i will try to check the wensite – elianore Feb 13 '13 at 22:51
-2

localStorage.clear without the () currently works in major browsers.

mdub
  • 1
  • 3
    Does it? `localStorage.clear` isn't a function call. `localStorage.clear()` **is**. And since [Clear localStorage](http://stackoverflow.com/q/7667958/691711) opts for `()`, I think that might be correct. – zero298 Mar 24 '14 at 23:55