-4

I want to get the elements within an ordered list using

var ListData = document.getElementById('MyList').innerHTML;

then I would like to store what's contained in the variable ListData to local storage. If possible, how would I go about saving the contents of that variable to localstorage? If this is not possible, I'll accept an alternative. Also, I'd like to know how to retrieve that data once it's saved. Thanks

Brandon
  • 101
  • 3
  • 10

1 Answers1

1

Yes, you can:

if (localStorage) { // Browser supports it
    localStorage.someKeyName = document.getElementById("MyList").innerHTML;
}

Details in the spec. There are also a large number of tutorials out there.

If you only need it for the duration of a current visit and not between visits, use sessionStorage instead of localStorage above.

Note that there are limits on the size of what you can store in web storage, and those limits may vary by browser.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875