I\'m learning javascript, xml, and html. For a homework assignment, I need to retrieve some data from some nodes of a XML file, concatenate the data, and store the concaten
localStorage.setItem('your_data_key', 'your_data')
I can't see anywhere in your code where you're storing something to localStorage
. You're trying to retrieve localStorage[students]
, but there's nothing there.
Note also that you can only store strings in localStorage
. You're assigning a jQuery result to students
at one point. Were you to try and store that in localStorage
it would fail as it's an array of jQuery obects.
You are not setting the data, you are getting the data that doesn't exist
I believe what you want is this
(You have to give a name to the variable in local storage, I'm giving it the name of students)
localStorage['students'] = students;
$("#clickme").text("Students' first names: " + students);
After this you can have your get if you want similar to what you had before
var s_data = localStorage['students'];
You can use the setItem() to set a value to the localStorage and getItem() to retrieve it
Ex:
localStorage.setItem('mykey', 'somevalue')
Demo: Fiddle