save text of div to localstorage 2c update localstorage when text is changed

Solutions on MaxInterview for save text of div to localstorage 2c update localstorage when text is changed by the best coders in the world

showing results for - "save text of div to localstorage 2c update localstorage when text is changed"
Nick
21 Aug 2020
1// get the text
2var text = $('#test').text();
3
4// set the item in localStorage
5localStorage.setItem('test', text);
6
7// bind text to 'blur' event for div
8$('#test').on('blur', function() {
9
10    // check the new text
11    var newText = $(this).text();
12
13    // overwrite the old text
14    localStorage.setItem('test', newText);
15
16    // test if it works
17    alert(localStorage.getItem('test'));
18
19});
20