I am trying to save in-session changes to an html table to localStorage so I can have the changes stay even after reload.
I’ve not tried anything yet as I heard localStorage can only save strings and I need to save a table
I am trying to save in-session changes to an html table to localStorage so I can have the changes stay even after reload.
I’ve not tried anything yet as I heard localStorage can only save strings and I need to save a table
2
Answers
You can save it as a string and convert it back to an array.
I think that you have 2 options:
localStorage.setItem('table', table.innerHTML)
and then, you can replace the table with that contenttable.innerHTML = localStorage.getItem('table')
)localStorage.setItem('table', JSON.stringify(data))
and thendata = JSON.parse(localStorage.getItem('table'))
and process it.