Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Storage Classes in HTML5
WhatsApp
Ankur Mishra
5y
4.4
k
0
0
25
Blog
Storage Classes in HTML5
Storage in HTML was done with the help of cookies. The exciting thing about this storage is that it's fast as well as secure.
Two types of storage are in HTML5
Local Storage:
In this object stores data for a larger period of time even if the browser is closed.
Session Storage:
In this object stores data for a specific session.
Methods
Using local storage in modern browsers is ridiculously easy. All you have to do is modify the localStorage object in JavaScript. You can do that directly use the setItem() and getItem() method:
localStorage.setItem('favoriteflavor','vanilla');
If you read out the favoriteflavor key, you will get back "vanilla":
var
taste
=
localStorage
.getItem('favoriteflavor');
// -
>
"vanilla"
To remove the item, you can use- the removeItem() method:
localStorage.removeItem('favoriteflavor');
var
taste
=
localStorage
.getItem('favoriteflavor');
// -
>
null
That's it! You can also use sessionStorage instead of localStorage if you want the data to be maintained only until the browser window closes.
Storage Classes in HTML5
Up Next
Align Div Horizontally and Responsive in HTML5
Ebook Download
View all
Frontend Developer Interview Questions and Answers
Read by 940 people
Download Now!
Learn
View all
Foreantech
Foreantech - A complete online solution company.
Membership not found