Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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'));

});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #save #text #div #update #localStorage #text #changed
ADD COMMENT
Topic
Name
7+5 =