<!DOCTYPE HTML> <html> <body> <script> function storeusername() { var person = {}; person.age = 25; person.firstname = 'Joe'; person.lastname = 'Smith'; localStorage.setItem('persondetails', JSON.stringify(person)); } function getusername() { var person = JSON.parse(localStorage.getItem('persondetails')); document.getElementById('username').innerHTML = person.age + ' ' + person.firstname + ' ' + person.lastname; } function clearusername() { localstorage.removeItem('personaldetails'); } </script> <br/> Name: <p id="username"></p> <input type=button value="Store" onclick="storeusername()" /> <input type=button value="Retrieve" onclick="getusername()" /> <input type=button value="Clear" onclick="clearusername()" /> </body> </html>
removeItem
persondetails
personaldetails
// localStorage is with capital S (very important, localstorage is undefined). // The key is persondetails, and not personaldetails. localStorage.removeItem('persondetails');
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)