I am trying to retreive key of a value which is in the browser local storage
But it returns same key for values which are stored in local storage but when i try to get value from key it give correct value.
I am trying to remove active element from html as well as its data which is stored in localstorage
function removefrom() {
const element = document.activeElement;
const key = localStorage.key(element.value);
localStorage.removeItem(key);
element.remove();
}
- first i will get active selected element
- i will pass active element's value from
element.value
(in line 2) - then i want to get key where the that value is in localstorage and then i will find key from passed value
- in line 4, i will remove item from local storage from key
- i will remove element from the dom