Im playing with HTML5 LocalStorage and it seems pretty straight forward for the most part.
Load the page with the following to insert the test values.
localStorage.setItem("artist-0", "0"); //saves to the database, key/value
localStorage.setItem("artist-1", "1");
localStorage.setItem("artist-2", "2");
localStorage.setItem("artist-3", "3");
I then generate a list from the stored data.
var hideartist = '';
for (var i = 0; i < localStorage.length; i++){
hideartist += "<li id=\\"artist-" + localStorage.getItem("artist-"+i) + " \\">" + localStorage.getItem("artist-"+i) + "</li>";
}
//alert(hideartist); // show hideartist
$('#artisthidelist').append(hideartist); // add top artists
However, when I try and remove a value using a key that’s generated by grabbing the id atribute of an element from jquery it just seems to fail.
Im struggling with is below. I can see from the alert that the ‘key’ seems to be Ok.
$("#artisthidelist li").live("click", function () {
var deletenum = '';
var deletenum = $(this).attr("id")
alert(deletenum);
localStorage.removeItem(deletenum);
});
Any ideas what Im doing wrong? I’ve set up a test page here