I want to be able to delete the value but the not the key from the local storage, any clue?
$(".delete").on("click", function() {
localStorage.removeItem('Property');
});
I want to be able to delete the value but the not the key from the local storage, any clue?
$(".delete").on("click", function() {
localStorage.removeItem('Property');
});
Try to use setItem() and set the value as null
or blank
like,
$(".delete").on("click", function() {
localStorage.setItem('Property',"");
});
Updated as per @qutz comment, If you have multiple items then first you need to store values in JSON format then you will be able to parse and splice to remove a single item like,
$(".delete").on("click", function() {
var ar = JSON.parse(localStorage.getItem("Property")),
item='color';// let we wants to remove color property from json array
var index = ar.indexOf(item);
if (index > -1) { // if color property found
ar.splice(index, 1);// then remove it
}
// again set the property without having color
localStorage.setItem("Property", JSON.stringify(ar));
});
Hope this will help you, may be some changes are required as per your logic and method which you've used for it.