Reputation: 19
I am trying to implement HTML5 contenteditable list item with session storage.
I am able edit the list item in the browser, but the changes are not getting stored in session storage.
please help me with the code below. Thanks is advance.
HTML
<ul contenteditable=true>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
<li>Menu 5</li>
</ul>
jQuery
$('ul').blur(function(){
sessionStorage.getItem('loadSessionStorage', $(this).html());
});
if(sessionStorage.getItem('loadSessionStorage')){
$('ul').html(sessionStorage.setItem('loadSessionStorage'));
}
Upvotes: 1
Views: 181
Reputation: 231
You have to use "setItem"
in "blur"
function and "getItem"
in "if"
condition.
As mentioned in the below code.
$('ul').blur(function(){
sessionStorage.setItem('loadSessionStorage', $(this).html());
});
if(sessionStorage.getItem('loadSessionStorage')){
$('ul').html(sessionStorage.getItem('loadSessionStorage'));
}
Upvotes: 1