I am trying to use local storage for my little table where i just want to save few things here is my current code:
$("#dodaj").click(function()
{
var str = "<tr onclick='Oznaci(this)'><td>"+stevilka+"</td><td>"+naslov+"</td><td>"+vrsta+"</td><td>"+nujnost+"</td><td>"+datum+"</td></tr>";
$("#tabela").append(str);
localStorage.podatki = localStorage.podatki + str;
});
$("#odstrani").click(function()
{
{
$(".rdeca").remove();
localStorage.removeItem(".rdeca");
}
});
function Oznaci(vrstica)
{
$(vrstica).css({"background-color":"#FF0000"});
$(vrstica).attr("class","rdeca");
}
I sucessfully add to the localStorage, but when i call localStorage.removeItem(".rdeca");
it does not remove it. I am probably removing the wrong thing (.rdeca). As i should probably remove the string bined like str from it, but i dont know how i can manage to do thath. THanks for your help
I am trying to use local storage for my little table where i just want to save few things here is my current code:
$("#dodaj").click(function()
{
var str = "<tr onclick='Oznaci(this)'><td>"+stevilka+"</td><td>"+naslov+"</td><td>"+vrsta+"</td><td>"+nujnost+"</td><td>"+datum+"</td></tr>";
$("#tabela").append(str);
localStorage.podatki = localStorage.podatki + str;
});
$("#odstrani").click(function()
{
{
$(".rdeca").remove();
localStorage.removeItem(".rdeca");
}
});
function Oznaci(vrstica)
{
$(vrstica).css({"background-color":"#FF0000"});
$(vrstica).attr("class","rdeca");
}
I sucessfully add to the localStorage, but when i call localStorage.removeItem(".rdeca");
it does not remove it. I am probably removing the wrong thing (.rdeca). As i should probably remove the string bined like str from it, but i dont know how i can manage to do thath. THanks for your help
-
1
I think you need to use
localStorage.removeItem("rdeca")
– Arun P Johny Commented Jan 30, 2013 at 16:15 - Nope it does not work too. – HyperX Commented Jan 30, 2013 at 16:16
-
Where are you setting the
.rdeca
item? I only see you setting thepodatki
item. – apsillers Commented Jan 30, 2013 at 16:17 -
I mark the clicked lines in table with red color, and this lines should be removed from the
localStorage
when i click delete. – HyperX Commented Jan 30, 2013 at 16:19
2 Answers
Reset to default 8The only assignment to localStorage
that's shown in your code is this:
localStorage.podatki = localStorage.podatki + str;
The name of the item you stored is podatki
so you need to remove it using that name:
localStorage.removeItem("podatki")
If your goal is to remove just a part of the value stored under that name, then you'll need to perform that operation manually. That is, you'll need to read the property, modify it as needed, and then write back to it.
The item in localstorage has no jQuery methods to update it.
You need to manually pull the stuff out of localstorage, delete the node, and reinsert it.