Raffy T Lawrence Raffy T Lawrence - 4 months ago 7
HTML Question

JavaScript: How to save html text in HTML5 localStorage

I need to save my appended html() text, every time i click the button it should be store in HTML 5 local storage.

$('#add_new_criteria').on('click',function(){
$('#cyc_append').html(': Add new another criteria');
localStorage.setItem( ???? );

});

Answer
$('#add_new_criteria').on('click',function(){
     $('#cyc_append').html(': Add new another criteria');
     localStorage.setItem('textKey', $('#cyc_append').html());

});

The first argument is the identifier you’ll later use to get the data out again. The second is the data you want to store.

Read more on localStorage

Comments