Raffy T Lawrence
Raffy T Lawrence

Reputation: 355

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( ???? );

});

Upvotes: 1

Views: 442

Answers (2)

Deathcr47
Deathcr47

Reputation: 53

localStorage.setItem('key','value');

you can check result in Chrome Console -> Resources -> Local Storage whether it is getting saved.

Refer following link https://developer.mozilla.org/en/docs/Web/API/Window/localStorage

Upvotes: 0

Amar Singh
Amar Singh

Reputation: 5622

$('#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

Upvotes: 2

Related Questions