SAVING YOUR TO-DO LIST ITEMS to localStorage : The user can now add and remove as many items as they need from the list.

But you might have noticed that if you refresh your page, your to-do list disappears. This is because so far we’ve just added or removed HTML elements from our screen. We haven’t saved the list or changed our HTML file.

If we want our browser to save and remember our list, we need to use localStorage, a handy API that’s available in HTML5 (the fifth version of the HTML programming language).

This API lets you save information in your browser, so even if your page is refreshed or closed you can still access the data. Like the DOM, localStorage is a collection of functions, and it’s simple to use.

All you have to do is tell your browser you want to use localStorage by typing the localStorage keyword (written in camelCase) and giving a name to the information you want to store.

Set the value of the information you want to store using an equals sign (=) and double quotes (” “), like this:

[javascript] localStorage.storageName = "information"; //added "information" text[/javascript]

If you want to remove a piece of information from localStorage, you just leave an empty value, like this:

[javascript] localStorage.storageName = ""; //"information" text removed.[/javascript]

Remember the // implies a line of commenting after the // NOT before.

Viewing the information you save using localStorage is simple. All you have to do is use the keyword and the localStorage name, like this:

[html] <!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<script>
localStorage.nameApp = "Hello World!";
alert(localStorage.nameApp);
</script>
</body>
</html>[/html]

Connected through code, Choose Your Platform!

About the Author: Bernard Aybout

In the land of bytes and bits, a father of three sits, With a heart for tech and coding kits, in IT he never quits. At Magna's door, he took his stance, in Canada's wide expanse, At Karmax Heavy Stamping - Cosma's dance, he gave his career a chance. With a passion deep for teaching code, to the young minds he showed, The path where digital seeds are sowed, in critical thinking mode. But alas, not all was bright and fair, at Magna's lair, oh despair, Harassment, intimidation, a chilling air, made the workplace hard to bear. Management's maze and morale's dip, made our hero's spirit flip, In a demoralizing grip, his well-being began to slip. So he bid adieu to Magna's scene, from the division not so serene, Yet in tech, his interest keen, continues to inspire and convene.