Reputation: 4599
var data = {
"mid":"10000XXX",
"css":{
"header":{
"background-color":"#000",
"color":"#fff",
"font-size":"10"
},
"txndescr":{
"background-color":"#000",
"color":"#fff",
"font-size":"10"
}
}
};
I have stored in the localstrorage in the following way,
// Put the object into storage
localStorage.setItem('defaultTheme', JSON.stringify(data));
And i want to update the 'header' background-color (#000 to #FFF) property. how to update the value.
Upvotes: 0
Views: 357
Reputation: 3565
The way to update an Object already in localStorage is as follows:
Save the updated item
//1. Fetch the existing item
var data = JSON.parse(localStorage.getItem('defaultTheme'));
//2. Update the value
data.css.header['background-color'] = '#CCC';
//3. Save the update item
localStorage.setItem('defaultTheme', JSON.stringify(data));
Cheers
Upvotes: 2