Answers for "set localstorage text html"

27

javascript set local storage value

var testObject = { 'one': 1, 'two': 2, 'three': 3 };

// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));

// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');

console.log('retrievedObject: ', JSON.parse(retrievedObject));
Posted by: Guest on March-07-2020
0

js localstorage add text

localStorage.setItem('username','myusername');
Now get the stored key

localStorage.getItem('username') //myusername
Posted by: Guest on August-25-2021
0

save text of div to localStorage, update localStorage when text is changed

// get the text
var text = $('#test').text();

// set the item in localStorage
localStorage.setItem('test', text);

// bind text to 'blur' event for div
$('#test').on('blur', function() {

    // check the new text
    var newText = $(this).text();

    // overwrite the old text
    localStorage.setItem('test', newText);

    // test if it works
    alert(localStorage.getItem('test'));

});
Posted by: Guest on June-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language