localStorage - object HTMLTableRowElement

0

I'm trying to save changes to the html code of my page made by a javaScript interaction. More precisely, I want the table I create with js to keep the html changes saved.

localStorage.setItem("resposta", document.querySelector("#tabela-anagrama"));

localStorage.getItem("resposta")

When I do a console.log to see what is written in the localStorage the response is [object HTMLTableRowElement]

My question is the following how do I record the html code and cause when I refresh the page the table comes back already with the changes recorded?

    
asked by anonymous 03.03.2018 / 04:27

1 answer

0

Use the outerHTML attribute. It will return the HTML tag of the element.

localStorage.setItem("resposta", document.querySelector("#tabela-anagrama").outerHTML);

Disadvantage:

This has a drawback, in case you want to add a lot of data, the setItem method will return a Exception due to lack of space.

Here is a table with the size available, per browser, for Local Storage :

    
03.03.2018 / 04:37