Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a part of html to local storage later load

Tags:

I need to save contents of a html div (id=tabela) to localstorage, so that the contents of the table can be loaded in another session via localstorage. How to get the div contents into a variable?

var = tabelaContent; //<-- I need contents of <div id=tabela> in this 
localStorage.setItem("tabelaContent",tabelaContent);

// then, upon pressing the "load" button

localStorage.getItem(tabelaContent);

FYI if there is another way of making the table's content persistent, let me know

TIA.

like image 334
Stan Kenway Avatar asked May 09 '16 18:05

Stan Kenway


1 Answers

You can use document.getElementById("myID").innerHTML, like this:

var = tabelaContent; 

tabelaContent = document.getElementById("tabela").innerHTML
localStorage.setItem("tabelaContent",tabelaContent);
like image 111
ScaisEdge Avatar answered Oct 13 '22 12:10

ScaisEdge