

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Retrieve element from local storage in JavaScript?
To retrieve an element from the local storage we have to check whether the browser endorses the local storage or not. Later, we have to set an element in the local storage. At this moment we have to be careful because once the browser is closed, no data will be stored in the local storage. Later on, we need to retrieve the data that is stored in the local storage. Let's discuss it in a nutshell.
To set data in the local storage the following is the syntax
localStorage.setItem();
Example
In the following example, initially, the Compatability of the storage is checked, using if condition. Later on, using localStorage.setItem() an item is placed in the local storage. Once the item is in the local storage, using the property localStorage.getItem() the data is retrieved.
<html> <body> <p id = "storage"></p> <script> if (typeof(Storage) !== "undefined") { localStorage.setItem("product", "Tutorix"); document.getElementById("storage").innerHTML = localStorage.getItem("product"); } else { document.getElementById("storage").innerHTML = "Sorry, no Web Storage compatibility..."; } </script> </body> </html>
Output
Tutorix
- Related Questions & Answers
- Thread-local storage (TLS)
- Storing Credentials in Local Storage
- Difference between Session Storage and Local Storage in HTML5
- Set the value in local storage and fetch – JavaScript?
- Retrieve an element from ArrayList in Java
- HTML DOM Local Storage clear() method
- Trick to store credentials in local storage
- Retrieve the last element from a LinkedList in Java
- Android 4.0.1 breaks WebView HTML 5 local storage?
- Checking if a key exists in HTML5 Local Storage
- What is the difference between local storage vs cookies?
- HTML 5 local Storage size limit for sub domains
- How to save cache in local storage of android webview?
- How to save database in local storage of android webview?
- How to store a name permanently using HTML5 Local Storage?
Advertisements